I’m currently in pdb trace to figure this out
ipdb> isinstance(var, Type)
False
ipdb> type(var)
<class 'module.Type'>
ipdb> Type
<class 'module.Type'>
Why can this happen?
P. S. isinstance(var, type(var)) returns True as expected
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I can only guess, but if you do in
modulethen both types look like
<class 'module.Type'>, but are nevertheless different.You could check that with
or with
Note that these comparisons work for both old-, and new-style classes.
For new-style classes, they are equivalent to
print(Type is type(var)).But this is not the case for old-style classes.
Another quite common trap is that you call this module with
or
making it known as
__main__module. If it is imported somewhere else under its true name, it is known under that name as well with a different name space.Another guess could be that you are working with ABCs or otherwise let the class have a
__instancecheck__()method.