Coverage status reported for "not TYPE_CHECKING" blocks
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
I'm not sure whether this qualifies as a bug, feature request or discussion.
I have a code base that I want to be able to run on Python 3.5 (the version in Debian stable at the moment), without introducing additional runtime dependencies (depending on typing_extensions while type checking is fine, but I don't want to force every end user to install it). Therefore, I made the following workaround for NoReturn:
# NoReturn was introduced in Python 3.6.5.
if TYPE_CHECKING:
from typing_extensions import NoReturn
else:
NoReturn = None
This works fine, both at runtime and when type checking. However, when I ask mypy to produce a coverage report, the NoReturn = None line shows up red.
Other code I put in the else body, for example a print statement, also shows up red. My guess is that mypy doesn't type check the else body because TYPE_CHECKING is True and then marks all code that it doesn't have information on as red.
I use the coverage report to see if there is anything regarding type hinting that can be improved in modules and these red lines from not TYPE_CHECKING blocks are noise that makes it harder to spot areas that could be improved. So for my use case, it would be better if blocks that are deliberately unchecked would be marked in either green or a new low-attention color like white or grey.
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, mypy's Verarbeitung von Coverage-Berichten für TYPE_CHECKING-Verzweigungen nachzuverfolgen und zu vergleichen, wie der else-Block klassifiziert wird. Die Arbeit ist abgeschlossen, wenn absichtlich nicht geprüfter Code in Blöcken mit not TYPE_CHECKING nicht mehr als bearbeitungsbedürftige rote Coverage erscheint, während gewöhnlicher nicht abgedeckter Code weiterhin unterscheidbar bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100