Improve the `help()` of type alias objects
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Feature or enhancement
EDIT: See https://discuss.python.org/t/runtime-docstrings-for-type-aliases/108901
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece reproduzindo a saída atual de help(x) para um alias de tipo na REPL e, em seguida, rastreie o tratamento de objetos de alias de tipo por help() e a implementação de aliases de tipo em tempo de execução. Está concluído quando for possível registrar strings de documentação em tempo de execução e help(Pair) apresentar o alias, sua documentação e os atributos relevantes sem descrever o alias de forma enganosa como a classe TypeAliasType.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- developer-experience
- Tipo de issue
- Funcionalidade
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Ativa
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 55/100