Skip to content

Mucking with sys.path breaks checking imports #13701

Closed as not planned
Closed as not planned
@dmtucker

Description

@dmtucker

Bug Report

If the first 2 entries of sys.path are pwd, mypy seems to miss type checks in imported modules.

To Reproduce

mypy==0.971

# sscce.py
import sys
import mypy.api
sys.path.insert(0, sys.path[0])
print(mypy.api.run(["good.py"])[0])
# good.py
import bad
# bad.py 
foo: str = 5

Expected Behavior

bad.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
Found 1 error in 1 file (checked 1 source file)

Actual Behavior

Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 0.971

This issue broke pytest-mypy tests which use pytester.runpytest_subprocess to run pytest in a subprocess (see realpython/pytest-mypy#139).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions