function is lacking a `__signature__` attribute
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
PEP-362 specifies that in order to cache the signature of any function, it is possible for the user to set its __signature__ attribute.
Actual
This attribute is not set in the builtins module over at https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1009
As a result a typechecker might reject the following piece of code
from inspect import signature
def main():
def f():
pass
f.__signature__ = signature(f)
if __name__ == "__main__":
main()
e.g. with pyright I have a false positive
/Users/leogermond/Lab/python/signature/main.py
/Users/leogermond/Lab/python/signature/main.py:9:7 - error: Cannot assign to attribute "__signature__" for class "function"
Attribute "__signature__" is unknown (reportFunctionMemberAccess)
1 error, 0 warnings, 0 informations
Expected
I would the __signature__ attribute to be specified in the function class (with a special marker indicating it's optional?) of the builtins module. A type checker such as pyright could then infer that setting this attribute is possible and accept the piece of code given in example.
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
Beginnen Sie bei stdlib/builtins.pyi ungefähr in Zeile 1009 und prüfen Sie, wie die function class deklariert ist. Vergleichen Sie die angeforderte Unterstützung für signature mit PEP 362 und dem bereitgestellten Zuweisungsbeispiel und verifizieren Sie anschließend, dass ein Typechecker wie pyright sie akzeptiert, sobald die Stub-Änderung vollständig ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 55/100