summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2022-12-16 20:30:47 (GMT)
committerGitHub <noreply@github.com>2022-12-16 20:30:47 (GMT)
commita5a7cea202d34ca699d9594d428ba527ef7ff2ce (patch)
tree5176c390d975ad480718c43245f02a78a55a2b39 /Lib/enum.py
parent5234e1cbea686e38392f113707db322ad8405048 (diff)
downloadcpython-a5a7cea202d34ca699d9594d428ba527ef7ff2ce.zip
cpython-a5a7cea202d34ca699d9594d428ba527ef7ff2ce.tar.gz
cpython-a5a7cea202d34ca699d9594d428ba527ef7ff2ce.tar.bz2
gh-100039: enhance __signature__ to work with str and callables (GH-100168)
Callables should be either class- or static-methods. Enum now uses the classmethod version to greatly improve the help given for enums and flags.
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index a0cad06..21f6388 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -685,7 +685,7 @@ class EnumType(type):
'member order does not match _order_:\n %r\n %r'
% (enum_class._member_names_, _order_)
)
-
+ #
return enum_class
def __bool__(cls):
@@ -1083,6 +1083,13 @@ 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'