Skip to content

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

Open

Description

@sobolevn

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

Activity

  1. self-assigned this
    on Jan 29, 2025
  2. sobolevn commented on Jan 29, 2025

    @sobolevn
    MemberAuthor

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

  3. tyralla commented on Jan 29, 2025

    @tyralla
    Collaborator

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

  4. sobolevn commented on Jan 30, 2025

    @sobolevn
    MemberAuthor

    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

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions