[ python-Bugs-1249615 ] isinstance() fails depending on how modules imported

SourceForge.net noreply at sourceforge.net
Mon Aug 1 16:54:05 CEST 2005


Bugs item #1249615, was opened at 2005-08-01 14:54
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1249615&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Hugh Gibson (hgibson50)
Assigned to: Nobody/Anonymous (nobody)
Summary: isinstance() fails depending on how modules imported

Initial Comment:
I have found an inconsistency with instance type 
checking dependent on how modules are imported. 
Using Windows 2000, Python 2.4.1.

Source files are attached. Unzip preserving paths. To 
run, open a cmd window and set PythonPath to the 
location of the "system" folder. Run ServerRun.py.

The program creates two class instances in two different 
modules, then calls a class function on one instance 
which takes as parameter the second instance. A call to 
isinstance to check if the parameter is of the correct 
class fails. 

If a parameter is passed to ServerRun.py then the class 
module is imported in a different way (specifying the 
path to the class) and the isinstance check succeeds.

The output shows that before the call to the class 
function, an isinstance() call succeeds in both cases.

There is obviously an easy fix in code, but I think that 
isinstance checking should not depend on how modules 
are imported. And, if I am using an incorrect module 
import sequence, that sequence should be disallowed.

Sample output (also showing Windows 2000 version) is:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\system\server>set pythonpath=c:\system

C:\system\server>serverrun
ServerRun:
   oNew.__class__ == 
<class 'Stream.Stream.CElement'>
   Stream.CElement == 
<class 'Stream.Stream.CElement'>
   isinstance(oNew, Stream.CElement) == True
AddField():
   oNew.__class__ == 
<class 'Stream.Stream.CElement'>
   CElement == 
<class 'server.Stream.Stream.CElement'>
   isinstance(oNew, CElement) == False

C:\system\server>serverrun 1
ServerRun:
   oNew.__class__ == 
<class 'server.Stream.Stream.CElement'>
   Stream.CElement == 
<class 'server.Stream.Stream.CElement'>
   isinstance(oNew, Stream.CElement) == True
AddField():
   oNew.__class__ == 
<class 'server.Stream.Stream.CElement'>
   CElement == 
<class 'server.Stream.Stream.CElement'>
   isinstance(oNew, CElement) == True

C:\system\server>

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1249615&group_id=5470


More information about the Python-bugs-list mailing list