This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients baskakov, eric.smith
Date 2021-08-16.06:05:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629093916.94.0.547898291519.issue44922@roundup.psfhosted.org>
In-reply-to
Content
You're importing main.py twice. The first is when you run "python main.py", where it has the module name '__main__'. The second time is in codegen.py, where it has the name 'main'. You create the AtomX instance as __main__.AtomX, but the isinstance check is against main.AtomX. Because the objects have different modules, they're not equal.

You can see this if you change the isinstance check to:

=============
from main import AtomX
import sys

def inheritance_map(candidate):
    assert isinstance(candidate, sys.modules['__main__'].AtomX)
==============

Another way to see this if you add a print statement to the original codegen.py:

==============
from main import AtomX

def inheritance_map(candidate):
    print(f'{candidate=} {type(candidate)=} {AtomX=}')
    assert isinstance(candidate, AtomX)
==============

Which will print:
candidate=AtomX(my_symbol='qwerty', quantity='') type(candidate)=<class '__main__.AtomX'> AtomX=<class 'main.AtomX'>
Notice the types refer to different modules, so they are distinct and unequal.

The easiest way around this is to not do any work in main.py, but instead create another module, import it from main.py, and do the work there.
History
Date User Action Args
2021-08-16 06:05:16eric.smithsetrecipients: + eric.smith, baskakov
2021-08-16 06:05:16eric.smithsetmessageid: <1629093916.94.0.547898291519.issue44922@roundup.psfhosted.org>
2021-08-16 06:05:16eric.smithlinkissue44922 messages
2021-08-16 06:05:16eric.smithcreate