mypy does not show error in excluded folder when PYTHONPATH set
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
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 mit dem reproduzierten Paketlayout, das excluded_folder/excluded.py und included_folder/included.py enthält, und vergleiche dann die beiden mypy-Befehle mit und ohne PYTHONPATH=. Verfolge, wie --exclude und importierte Module gefunden werden. Erledigt ist die Aufgabe, wenn der Aufruf mit PYTHONPATH=. den inkompatiblen Rückgabewert in excluded.py meldet und ein Regressionstest beide Befehle abdeckt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers, devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100