Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@gvanrossum

Description

@gvanrossum
Issue body actions

Example:

from typing import Dict
from enum import Enum
class E(Enum):
    V = 'V'
d = {}  # type: Dict[E, int]
def f(s: str):
    e = E[s]  # type: ignore
    d[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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.