Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enum values on enum class can't be reassigned or deleted #7385

Closed
@erictraut

Description

@erictraut

The EnumMeta class in enum.pyi was recently modified to include a __setattr__ and __delattr__ method. These were flagged as a bug in pyright's unit tests because an attempt to set or delete an attribute on an enum class results in a runtime error.

from enum import Enum

class Color(Enum):
    red = "red"

# This should generate an error because reassignment of enum
# values is not allowed.
# Note: A change to typeshed's enum.pyi breaks this test.
Color.red = "new"  # Runtime exception

The above code is no longer flagged as an error by pyright although it generates a runtime exception.

@AlexWaygood, I think you submitted the PR for this change. Was the addition of __setattr__ and __delattr__ intentional?

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