Skip to content

Wrong Signature for Enum with Specific Dataclass Mixin Scenario #15908

Description

@iFailatGitHub

Note: I was thinking about putting this on pyright but it said standard library problems are more suited here, so I'll give it a shot.

I was trying to code an enum with a dataclass mixin where each value is overridden through the first string variable for easier referencing (rather than a dict from str to enum).

from dataclasses import dataclass
from enum import Enum, auto

@dataclass(frozen=True)
class SampleMixin:
    a_string: str
    a_number: int

class SampleEnum(SampleMixin, Enum):
    def __new__(cls, value: str, *_):
        obj = object.__new__(cls)
        obj._value_ = value

        return obj

    foo = "foo", 1
    bar = "bar", 2

class SampleEnum2(Enum):
    foo = auto()
    bar = auto()

baz = SampleEnum("foo")
qux = SampleEnum2("foo")

baz still gets SampleEnum.foo right, but the function signature is incorrectly identified. Ideally, it should be closer to SampleEnum2's function signature.

Image

I'm open to workarounds at the meantime. The code runs correctly, it's just that the inferred signature I got was wrong.

Code sample in pyright playground.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions