Feature or enhancement
Proposal:
Consider recording __doc__ on type alias objects.
For instance:
type Pair[T] = tuple[T, T]
"""A pair of values of the same type."""
Now Pair.__doc__ is "A pair of values of the same type.".
Use it in the REPL:
>>> from mymodule import Pair
>>> help(Pair)
Help on type alias Pair in module mymodule:
Pair[T] = tuple[T, T]
| A pair of values of the same type.
|
| Attributes:
|
| __value__
| Lazily evaluated value of the type alias.
|
| evaluate_value
| Evaluation function for __value__.
|
| __type_params__
| Type parameters declared by the type alias.
|
| __parameters__
| Type parameters after expansion.
|
| __name__
| Name of the type alias.
|
| __qualname__
| Qualified name of the type alias.
|
| __module__
| Module in which the type alias was defined.
(I wrote this text by hand, the actual thing could probably be improved.)
I assume IDEs/LSPs already catch it, so this is mainly a runtime feature.
Current help() just shows a slightly confusing help on the type alias type itself:
>>> type x = int
>>> help(x)
Help on TypeAliasType in module __main__ object:
x = class TypeAliasType(builtins.object)
| Type alias.
|
| Type aliases are created through the type statement::
|
...
It is confusing because (1) it reads like TypeAliasType was defined in __main__ (Help on TypeAliasType in module __main__ object), and (2) almost like if i did x = typing.TypeAliasType. (Which could be improved on its own? We could instead say x = instance of class ..., not just x = class ...)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Feature or enhancement
Proposal:
Consider recording
__doc__on type alias objects.For instance:
Now
Pair.__doc__is"A pair of values of the same type.".Use it in the REPL:
(I wrote this text by hand, the actual thing could probably be improved.)
I assume IDEs/LSPs already catch it, so this is mainly a runtime feature.
Current
help()just shows a slightly confusing help on the type alias type itself:It is confusing because (1) it reads like
TypeAliasTypewas defined in__main__(Help on TypeAliasType in module__main__object), and (2) almost like if i didx = typing.TypeAliasType. (Which could be improved on its own? We could instead sayx = instance of class ..., not justx = class ...)Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response