Skip to content

Enum.value typed as Any when using functools.cache #19368

Open
@kmurphy4

Description

@kmurphy4

Bug Report

If I define a method with @functools.cache on an Enum, then the type of that Enum's value attr becomes Any. Without the @functools.cache annotation, it gets typed correctly.

Also, this behavior does not occur if you use enum literals - i.e., Foo.BAR.value is typed correctly, but foo.value (for a foo: Foo) is wrong.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&gist=b2a218b8db8367b2ac62dcf583a8c4f7

Expected Behavior

The type assertion in frobnicate() should succeed.

Actual Behavior

The type assertion in frobnicate() fails 😿.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions