Improving the type signature of `setattr`
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
When the first argument of setattr is of type NoneType or EllipsisType the function will always raise an AttributeError on runtime, so it would be nice if the following calls would be detected as type errors.
x = None
setattr(x, 'foo', True) # AttributeError: 'NoneType' object has no attribute 'test'
y = ...
setattr(y, 'foo', True) # AttributeError: 'ellipsis' object has no attribute 'test'
I am not sure what's the best way to go about this is, there are probably many builtin types that do not support arbitrary attributes to be set. We do not appear to have a type to categorize such types, which could then in the future be used with Not[], once python/typing#801 is implemented.
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
Beginne damit, den typeshed-Stub für das eingebaute setattr zu finden, und sieh dir die zugehörige Diskussion in python/typing#801 an. Ermittle, wie die Signatur NoneType und EllipsisType ablehnen sollte, ohne andere gültige Ziele fälschlicherweise auszuschließen; erledigt ist die Aufgabe, wenn die vorgesehenen Aufrufe als Typfehler gemeldet werden und bestehende setattr-Fälle weiterhin unterstützt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100