We hit some very weird behaviour recently while setting up a package hierarchy. Robin Becker managed to distil this into a simple example. Can anyone shed any light on what is happening below? Is Python behaving as it should? Create a package A, empty __init__.py, with modules as follows: --------parent.py---------- class Parent: pass --------child.py------------ from parent import Parent class Child(Parent): pass ---------test.py-------- from parent import * class Examiner: def examine(self, arg): print 'examining argument:' print 'class of arg =3D', arg.__class__ print 'bases of arg =3D', arg.__class__.__bases__ print 'arg =3D', arg if isinstance(arg, Parent): print "arg is an instance of Parent" else: print "arg IS NOT an instance of Parent" print =20 if __name__=3D=3D'__main__': from traceback import print_exc import sys def run0(): from A.child import Child e =3D Examiner() e.examine(Child()) def run1(): from A.child import Child from A.test import Examiner e =3D Examiner() e.examine(Child()) run0() run1() Running this script produces the following output: C:\users\andy\A>test.py examining argument: class of arg =3D A.child.Child bases of arg =3D (<class A.parent.Parent at 7f9150>,) arg =3D <A.child.Child instance at 7f9410> arg IS NOT an instance of Parent examining argument: class of arg =3D A.child.Child bases of arg =3D (<class A.parent.Parent at 7f9150>,) arg =3D <A.child.Child instance at 7f83c0> arg is an instance of Parent Many thanks, Andy Robinson
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4