Skip to content

Incorrect type inference for value of enum member with mixin #3159

Closed

Description

@DerBiasto

Describe the Bug

pyrefly infers a mixin type of an enum as the value of an enum member.

import enum
from typing import reveal_type


class Meta:
    pass


class MyEnum(Meta, enum.Enum):
    pass


class MyIntEnum(Meta, enum.IntEnum):
    pass


class Foo(MyEnum):
    bar = 1


class Bar(MyIntEnum):
    foo = 1


reveal_type(Foo.bar)  # Literal[Foo.bar]
reveal_type(Foo.bar.value)  # Meta

reveal_type(Bar.foo)  # Literal[Bar.foo]
reveal_type(Bar.foo.value)  # Meta

Imagine that the Meta class is simply providing some common methods for the different custom enum classes.

I imagine, that this could be related to or already resolved by #1982 but I'm not sure if that fix is even released yet.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABDOgK5UA66YduVTBqWIR0AcybVajJnRgA3GKigB9IcRjct6AMZRUcOEwCyMBqkTcm1psQNxt3PfZOkAouyoAKU%2BYA0LJ6EHhwAlJboNrb2jrr6hq4AkugMId6%2BqAGsHITJqZ7hVjZ2hrHOCQBiuLg%2B7gURUdiodEwAvEwAjGXxRgBCzbV5aYWRNmDVbZ2xcorKasIwXlW4hE10odwzSqrqi8urzYTyymwwG%2BibCtvzGl79dITjuOdbc7t3h09HJ2fcIH4gMhyMBQUiEBj8KAUADETAACqRgaCmGgsHh8EwdLgeBAxGw6KgGBBsYRuLCAMowGBMAAWDAYxDgiAA9MygTAQWD6GJmaxmZhcDo4MysTi8QSidjmUxxi1UMdoKhsLBMdjIOLCcTIrhiJL0HBSegyAwadiALSKOhwLWTTggADMhA6ACY7dwANowOh8K0AXW4bHQUnoDBgmDNmAgch0RMUkwA5Lj0PQYPHuMmGGa5ABHNhRsNmgDWMFIZtQOh08CM7XjAHdmug0%2BgQABfAHl2MwCrQGAUVE4AgkcgtoA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. NathanTempest commented on Apr 16, 2026

    @NathanTempest
    Contributor

    Thanks for reporting @DerBiasto Confirmed that Foo.bar.value incorrectly infers Meta instead of int on the latest build (v0.60.0).

    This is a separate issue from #1982 (which was about overload resolution with enum literals and is already fixed). The root cause here is in mixed_in_enum_data_type() — it treats the first non-Enum base class as the data type, but doesn't distinguish between actual data types (like int in IntEnum) and plain mixins (like Meta which just provides methods).

    cc @yangdanny97

  2. NathanTempest commented on Apr 16, 2026

    @NathanTempest
    Contributor

    Looks like an easy fix where we could differentiate between a datatype Enum class and a Mixin class by the use of new

    Assigning this to myself for the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions