Basically I have a project set up like so:
<container-folder>
|- <folder_1>
|- <extra_folder>
| |- source.py
|
|- main.py
And in main.py I declare a class like so:
class ClassOne:
pass
and in another method in main.py I have the following code:
result = source_function()
if not isinstance(result, ClassOne):
print "failed!"
In source.py, I define
import container-folder.folder_1.main
...
def source_function():
return main.ClassOne()
However, I still get "failed!" printed out. When examining in the debugger, I got a bit of an odd surprise:
result was marked as type container-folder.folder_1.main.ClassOne, and ClassOne has the signature main.ClassOne. Why are these two not considered equal?
I also noted that if I changed the code to the following, using its fully-qualified class name:
if not isinstance(result, container-folder.folder_1.main.ClassOne):
I get the expected success.
Aucun commentaire:
Enregistrer un commentaire