Improve the `help()` of type alias objects
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- developer-experience
Direzione di ricerca
Inizia riproducendo l’output attuale di help(x) per un alias di tipo nella REPL, quindi segui la gestione degli oggetti alias di tipo da parte di help() e l’implementazione degli alias di tipo a runtime. Il lavoro è completato quando è possibile registrare le stringhe di documentazione a runtime e help(Pair) presenta l’alias, la relativa documentazione e gli attributi pertinenti senza descrivere fuorviante l’alias come la classe TypeAliasType.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
docs pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
build type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
stdlib topic-email type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Tutte le issue di python/cpython
Issue simili
-
link-check link-check:sphinx-theme
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
OpenHands/extensions#626 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
CSCfi/sd-search-api#39 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100