Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marking a private Enum member as member() does not work #18563

Open
sobolevn opened this issue Jan 29, 2025 · 3 comments
Open

Marking a private Enum member as member() does not work #18563

sobolevn opened this issue Jan 29, 2025 · 3 comments
Assignees
Labels
bug mypy got something wrong topic-enum

Comments

@sobolevn
Copy link
Member

Consider this example:

from enum import Enum, member

class Pet(Enum):
    __CAT = member(1)

reveal_type(Pet.__CAT)  # N: Revealed type is "enum.member[Literal[1]?]"

Link: https://mypy-play.net/?mypy=latest&python=3.12&gist=63b056215c22ba7ff09e2559dd2ae08a

However, in runtimes it fails with AttributeError, because __CAT is mangled to _Pet__CAT as regular private names are.

We need to fix this corner-case.

Refs #18491
Refs #18557

@sobolevn
Copy link
Member Author

I also think that the revealed type should be just Literal[1] ...?

@tyralla
Copy link
Collaborator

tyralla commented Jan 29, 2025

PR #16715 deals with name mangling. Would it fix this issue as well?

@sobolevn
Copy link
Member Author

Yes, this problem is not related to Enum. It happens for all similar case:

from enum import Enum

class A:
    def __init__(self) -> None:
        self.__private = 1
        
A().__private  # false positive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-enum
Projects
None yet
Development

No branches or pull requests

2 participants