inspect.Signature doesn't display defaults as they appear in code
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Certain types of defaults show up in output of Signature instances as overly-verbose representations that don't match their syntax display.
>>> import inspect
>>> def a_test(a=str, b=inspect, c=inspect.Signature, d=inspect.signature, e=inspect.Signature.replace, f=(i for i in range(3))):
... """lots of objects with awkward reprs"""
...
>>> print(inspect.signature(a_test))
(a=<class 'str'>, b=<module 'inspect' from '/Users/jeremyp/git/cpython/Lib/inspect.py'>, c=<class 'inspect.Signature'>, d=<function signature at 0x10c77e980>, e=<function Signature.replace at 0x10c77fba0>, f=<generator object <genexpr> at 0x10c6d7100>)
>>>
>>> def b_test(a: str = str):
... """annotations seem to get this right"""
...
>>> print(inspect.signature(b_test))
(a: str = <class 'str'>)
The string representation of Signature is important as it is used, among other places, as the output of help and pydoc
>>> help(locale.atof)
Help on function atof in module locale:
atof(string, func=<class 'float'>)
Parses a string as a float according to the locale settings.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Lies zunächst die Einstiegspunkte inspect.signature und für die String-Darstellung von Signature, und reproduziere dann die Beispiele für Defaults mit Klassen, Modulen, Funktionen, Methoden und Generatoren. Vergleiche die Ausgabe mit der Verwendung von help und pydoc; abgeschlossen ist die Arbeit, wenn Signature Defaults in einer weniger übermäßig ausführlichen Form anzeigt und dabei nützliche Informationen für Aufrufer beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- developer-experience
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 28/100