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 <>
You're importing twice. The first is when you run "python", where it has the module name '__main__'. The second time is in, 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

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, but instead create another module, import it from, and do the work there.
Date User Action Args
2021-08-16 06:05:16eric.smithsetrecipients: + eric.smith, baskakov
2021-08-16 06:05:16eric.smithsetmessageid: <>
2021-08-16 06:05:16eric.smithlinkissue44922 messages
2021-08-16 06:05:16eric.smithcreate