python / python/mypy

Coverage status reported for "not TYPE_CHECKING" blocks

Aperta
#6,101 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

priority-1-normal topic-usability
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando la gestione dei report di coverage da parte di mypy per i rami TYPE_CHECKING e confronta il modo in cui viene classificato il corpo di else. Il lavoro è completato quando il codice deliberatamente non verificato nei blocchi not TYPE_CHECKING non appare più come coverage rossa su cui intervenire, mentre il normale codice non coperto rimane distinguibile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.