python / python/mypy

mypy does not show error in excluded folder when PYTHONPATH set

Aperta
#16,973 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

As far as I understand, when I use the exclude setting for some folder mypy should still show errors in these packages when imported, because of the follow imports logic. However, if I set the PYTHONPATH to the current working directory, it does not show these errors anymore.

To Reproduce
Here is the folder structure:

src/
|--excluded_folder/
|           |-- excluded.py
|           |-- __init__.py
|--included_folder/
            |-- included.py
            |-- __init__.py

The contents of the file excluded.py are as follows:

def function() -> str:  # obviously wrong return type
        return 5

File included.py looks like so:

from excluded_folder.excluded import function

print(function)

Now, if i run mypy like so, with the setting to exclude the excluded folder, it reports this:

$ mypy --strict --exclude excluded_folder src                          
src/excluded_folder/excluded.py:3: error: Incompatible return value type (got "int", expected "str")  [return-value]
Found 1 error in 1 file (checked 2 source files)

This is what i would expect. It still shows the errors in the file, although excluded.

But if i run mypy with PYTHONPATH set to the current working directory, it does not show any error anymore:

% PYTHONPATH=. mypy --strict --exclude excluded_folder src
Success: no issues found in 2 source files

Expected Behavior
Mypy should also show the errors when the PYTHONPATH is set.

Actual Behavior
Mypy does not show the errors when the PYTHONPATH is set.

Your Environment

  • Mypy version used: mypy 1.8.0 (compiled: yes)
  • Mypy command-line flags: see commands above
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.11.3

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 con la struttura del pacchetto riprodotta che contiene excluded_folder/excluded.py e included_folder/included.py, quindi confronta i due comandi mypy con e senza PYTHONPATH=. Traccia il modo in cui vengono individuati --exclude e i moduli importati. Il lavoro è completo quando l'invocazione con PYTHONPATH=. segnala il valore di ritorno incompatibile in excluded.py, con un test di regressione che copra entrambi i comandi.

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

Valutazione

Stack tecnologico
python
Ambito
compilers, 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.