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.

Title: After the subclass of enum.Enum is imported in some diffenent ways, the same enumeration value is judged as False
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Lcx994611818, ethan.furman
Priority: normal Keywords:

Created on 2021-01-18 07:31 by Lcx994611818, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit Lcx994611818, 2021-01-18 07:31
Messages (2)
msg385174 - (view) Author: Chenxi Liu (Lcx994611818) Date: 2021-01-18 07:31
When you run the in attachment, it will print a False but the two enumeration value which are acquired in different ways is same
msg385219 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-01-18 19:17
This issue is not unique to Enum, and is not an Enum problem.

What is happening is that "" has the `__name__` of `__main__` because it is being directly executed from the command line, but when `` imports it, it is being re-executed and everything inside is re-created -- so you end up with two copies of everything in that module.

You can also see this issue if you manage to import a module under two different names (usually by messing with `sys.path`).

To see it yourself, add a custom __str__ to A:

        def __str__(self):
            return "%s.%s.%s" % (
                   __qualname__, self._name_,

Then your print() will show:

    __main__.A.a test.A.a
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87119
2021-01-18 19:17:17ethan.furmansetstatus: open -> closed
resolution: not a bug
messages: + msg385219

stage: resolved
2021-01-18 17:38:57gvanrossumsetnosy: + ethan.furman
2021-01-18 07:31:23Lcx994611818create