-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow Python code to determine class help text #73549
Comments
From bpo-29338, msg286139: Color(value, names=None, *, module=None, qualname=None, type=None, start=1) Ethan, what are your thoughts? |
That that is very unhelpful help text. :( Better would be: Color(value) So how do we allow Python code to determine the help text? |
This line is came from the signature of the __call__ method. >>> import enum, inspect
>>> class A(enum.Enum):
... x = 1
...
>>> inspect.signature(A)
<Signature (value, names=None, *, module=None, qualname=None, type=None, start=1)>
>>> inspect.signature(A.__call__)
<Signature (value, names=None, *, module=None, qualname=None, type=None, start=1)>
>>> inspect.signature(enum.EnumMeta.__call__)
<Signature (cls, value, names=None, *, module=None, qualname=None, type=None, start=1)> But calling A with optional arguments doesn't work. >>> A(1)
<A.x: 1>
>>> A('B', {'y': 2})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/enum.py", line 293, in __call__
return cls._create_(value, names, module=module, qualname=qualname, type=type, start=start)
File "/home/serhiy/py/cpython/Lib/enum.py", line 378, in _create_
_, first_enum = cls._get_mixins_(bases)
File "/home/serhiy/py/cpython/Lib/enum.py", line 436, in _get_mixins_
raise TypeError("Cannot extend enumerations")
TypeError: Cannot extend enumerations |
There are actually two signatures: EnumCls(value) --> return member with value EnumCls(name, members, module, qualname, type, start) --> create new Enum An example of the first: class A(Enum):
x = 1
A(1) --> <A.x: 1> an example of the second: class A(Enum):
pass
B = A('B', {'y':2})
B(2) --> <B.y: 2> The reason for the error you see is that Enums with members cannot be further subclassed. |
I'm wondering is it worth to set different __call__ methods for enum types with and without members? |
Probably not because an enum class' __call__ comes from the type EnumMeta -- so having two different __call__ methods would mean two different metaclasses, and I'm pretty sure I don't want to go there. ;) There is a __doc__ defined for the __call__ method, though -- is there a reason inspect isn't using that? |
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: