Skip to content

Commit 0f2e87e

Browse files
authored
Make name and value read-only for Enums (#6576)
1 parent c3cd88b commit 0f2e87e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stdlib/enum.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,16 @@ if sys.version_info >= (3, 11):
9292
EnumType = EnumMeta
9393

9494
class Enum(metaclass=EnumMeta):
95-
name: str
96-
value: Any
95+
if sys.version_info >= (3, 11):
96+
@property
97+
def name(self) -> str: ...
98+
@property
99+
def value(self) -> Any: ...
100+
else:
101+
@types.DynamicClassAttribute
102+
def name(self) -> str: ...
103+
@types.DynamicClassAttribute
104+
def value(self) -> Any: ...
97105
_name_: str
98106
_value_: Any
99107
if sys.version_info >= (3, 7):

tests/stubtest_allowlists/py3_common.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ distutils.command.bdist_packager # It exists in docs as package name but not in
8383
distutils.version.Version._cmp # class should have declared this
8484
distutils.version.Version.parse # class should have declared this
8585
email.headerregistry.BaseHeader.max_count # docs say subclasses should have this property
86+
enum.Enum.name # A special property that exists at runtime, but stubtest can't detect https://github.com/python/typeshed/pull/6576#issuecomment-992538677
87+
enum.Enum.value # A special property that exists at runtime, but stubtest can't detect https://github.com/python/typeshed/pull/6576#issuecomment-992538677
8688
http.HTTPStatus.description # set in __new__
8789
http.HTTPStatus.phrase # set in __new__
8890
http.client.HTTPConnection.response_class # the actual type at runtime is abc.ABCMeta

0 commit comments

Comments
 (0)