When working on a project I stumbled upon a problem with isinstance(). I have made a simple example to ilustrate it:
test.py
import testAux
class Developer(object):
# Constructor
def __init__(self, name):
self.name = name
class PythonDeveloper(Developer):
# Constructor
def __init__(self, name, language):
self.name = name
self.language = language
# Object of PythonDeveloper
dev = PythonDeveloper("Eric", "Python")
if __name__=="__main__":
# is python_dev object an instance of a Developer Class
print(isinstance(dev, Developer))
# Output True
testAux.PassMeObject(dev)
testAux.py
from test import *
class PassMeObject():
def __init__(self, obj: PythonDeveloper) -> None:
print(isinstance(obj, Developer))
pass
Basically I instance PythonDeveloper an store it in dev and then pass this obj to PassMeObject.
I print isinstance(obj, Developer) from both places on the same variable. But the outputs are diferent:
True
False
How is this possible? How can I fix it?