Conditional annotations are always included in `STRING` annotations
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
If an annotation is excluded via a conditional block it is correctly excluded in VALUE and FORWARDREF annotations but is incorrectly included under STRING annotations.
from annotationlib import get_annotations, Format
class Example:
a: int
if False:
b: str
print(get_annotations(Example))
print(get_annotations(Example, format=Format.STRING))
{'a': <class 'int'>}
{'a': 'int', 'b': 'str'}
'b' should not be included in string annotations here.
CPython versions tested on:
3.14, 3.15, CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-156516
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
Reproduziere zunächst das Beispiel mit get_annotations und Format.STRING und untersuche anschließend die Implementierung von annotationlib und die relevanten Tests. Erledigt ist dies, wenn bedingte Annotationen wie b in den STRING-Ergebnissen fehlen, dem Verhalten von VALUE und FORWARDREF entsprechen und die Regression durch erfolgreiche Tests abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 25/100