summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorSergey B Kirpichev <skirpichev@gmail.com>2024-10-08 19:36:03 (GMT)
committerGitHub <noreply@github.com>2024-10-08 19:36:03 (GMT)
commiteafd14fbe0fd464b9d700f6d00137415193aa143 (patch)
tree487ad48da33c7761a45287a4c85f69c5dcc56201 /Lib/enum.py
parentb2a7272408593355c4c8e1d2ce9018cf96691bea (diff)
downloadcpython-eafd14fbe0fd464b9d700f6d00137415193aa143.zip
cpython-eafd14fbe0fd464b9d700f6d00137415193aa143.tar.gz
cpython-eafd14fbe0fd464b9d700f6d00137415193aa143.tar.bz2
gh-116110: remove extra processing for the __signature__ attribute (GH-116234)
This is an alternative to GH-100168.
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 9d53eb8..17d7273 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1092,6 +1092,21 @@ class EnumType(type):
# now add to _member_map_ (even aliases)
cls._member_map_[name] = member
+ @property
+ def __signature__(cls):
+ from inspect import Parameter, Signature
+ if cls._member_names_:
+ return Signature([Parameter('values', Parameter.VAR_POSITIONAL)])
+ else:
+ return Signature([Parameter('new_class_name', Parameter.POSITIONAL_ONLY),
+ Parameter('names', Parameter.POSITIONAL_OR_KEYWORD),
+ Parameter('module', Parameter.KEYWORD_ONLY, default=None),
+ Parameter('qualname', Parameter.KEYWORD_ONLY, default=None),
+ Parameter('type', Parameter.KEYWORD_ONLY, default=None),
+ Parameter('start', Parameter.KEYWORD_ONLY, default=1),
+ Parameter('boundary', Parameter.KEYWORD_ONLY, default=None)])
+
+
EnumMeta = EnumType # keep EnumMeta name for backwards compatibility
@@ -1135,13 +1150,6 @@ class Enum(metaclass=EnumType):
attributes -- see the documentation for details.
"""
- @classmethod
- def __signature__(cls):
- if cls._member_names_:
- return '(*values)'
- else:
- return '(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)'
-
def __new__(cls, value):
# all enum instances are actually created during class construction
# without calling this method; this method is called by the metaclass'