Skip to content

Adding # type: ignore to EnumClass[string_value] doesn't set the type to Any #2416

Description

@gvanrossum

Example:

fromtypingimportDictfromenumimportEnumclassE(Enum):
V='V'd= {} # type: Dict[E, int]deff(s: str):
e=E[s] # type: ignored[e] =0# Still error here

We have to use # type: ignore on the line e = E[s] because of #741. But somehow the type of e, when ignoring the error, is not Any but something else. So on the last line we get

__tmp__.py: note: In function "f":
__tmp__.py:8: error: Invalid index type "E" for "dict"

The weird thing is that if e had type E, d[e] would be valid, so the error is also somehow lying...

UPDATE: When trying to repro this, don't try E['V'] -- mypy sees the literal and gives some other error, probably also because of #741.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions