mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
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.
This commit is contained in:
parent
5234e1cbea
commit
a5a7cea202
5 changed files with 73 additions and 4 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue