Skip to content

mypy interprets variable as a type during Enum indexing #1381

@cduong

Description

@cduong

Example code, where row.status is expected to be a string:

class Status(Enum):
    SUCCEEDED = 1
    FAILED = 2

def get_status(row):
    # type: (Any) -> Status
    status = Status[row.status]
    return status

Error:

note: In function "test":
error: Invalid type "row"

In a similar case, I also received this error in addition to the above: error: Generic type not valid as an expression any more (use '# type:' comment instead)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions