Skip to content

Add support for enforcing type of _value_ in Enum class if it is declared #7030

@erictraut

Description

@erictraut

If an Enum class explicitly declares the type of the _value_ attribute, pyright should honor it and enforce type consistency.

from enum import Enum


class Color(Enum):
    _value_: int
    RED = 1 # OK
    GREEN = "green"  # Should be type error

class Planet(Enum):
    _value_: str

    def __init__(self, value: int, mass: float, radius: float):
        self._value_ = value # Shoudl be type error

    MERCURY = (1, 3.303e+23, 2.4397e6)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions