Skip to content

Make enums idempotent #19669

@randolf-scholz

Description

@randolf-scholz

Feature

Currently, passing an enum into its own constructor forgets its value:

from enum import IntEnum

class Foo(IntEnum):
    x = 0
    y = 1

reveal_type(Foo(Foo.x))  # reveals Foo, not Foo.x
reveal_type(Foo.__new__)  # "def [Self <: IntEnum] (cls: type[Self], value: builtins.int) -> Self" 
reveal_type(Foo.__init__) # "def (self: builtins.object)"

Pitch

It should be straightforward to synthesize a signature that makes Foo(Foo.x) inferred as Foo.x.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions