From 0f2e87e42aba29798013d3b11054c204a5e2b562 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 13 Dec 2021 15:08:49 +0000 Subject: [PATCH] Make `name` and `value` read-only for `Enum`s (#6576) --- stdlib/enum.pyi | 12 ++++++++++-- tests/stubtest_allowlists/py3_common.txt | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 20e4d9fc7..32eb2f4c7 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -92,8 +92,16 @@ if sys.version_info >= (3, 11): EnumType = EnumMeta class Enum(metaclass=EnumMeta): - name: str - value: Any + if sys.version_info >= (3, 11): + @property + def name(self) -> str: ... + @property + def value(self) -> Any: ... + else: + @types.DynamicClassAttribute + def name(self) -> str: ... + @types.DynamicClassAttribute + def value(self) -> Any: ... _name_: str _value_: Any if sys.version_info >= (3, 7): diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index a75e0c3af..612bd1cc5 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -83,6 +83,8 @@ distutils.command.bdist_packager # It exists in docs as package name but not in distutils.version.Version._cmp # class should have declared this distutils.version.Version.parse # class should have declared this email.headerregistry.BaseHeader.max_count # docs say subclasses should have this property +enum.Enum.name # A special property that exists at runtime, but stubtest can't detect https://github.com/python/typeshed/pull/6576#issuecomment-992538677 +enum.Enum.value # A special property that exists at runtime, but stubtest can't detect https://github.com/python/typeshed/pull/6576#issuecomment-992538677 http.HTTPStatus.description # set in __new__ http.HTTPStatus.phrase # set in __new__ http.client.HTTPConnection.response_class # the actual type at runtime is abc.ABCMeta