Skip to content

Add mypy_path config option (#2323) #2329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ The following global flags may only be set in the global section
alternative directory which is used to look for stubs instead of the
default ``typeshed`` directory.

- ``mypy_path`` (string) specifies the paths to use, after trying the paths
from ``MYPYPATH`` environment variable. Useful if you'd like to keep stubs
in your repo, along with the config file.

- ``warn_incomplete_stub`` (Boolean, default False) warns for missing
type annotation in typeshed. This is only relevant in combination
with ``check_untyped_defs``.
Expand Down
3 changes: 3 additions & 0 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def build(sources: List[BuildSource],
# to the lib_path
lib_path.insert(0, os.getcwd())

# Prepend a config-defined mypy path.
lib_path[:0] = options.mypy_path

# Add MYPYPATH environment variable to front of library path, if defined.
lib_path[:0] = mypy_path()

Expand Down
1 change: 1 addition & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ def get_init_file(dir: str) -> Optional[str]:
'strict_optional_whitelist': lambda s: s.split(),
'custom_typing_module': str,
'custom_typeshed_dir': str,
'mypy_path': lambda s: [p.strip() for p in re.split('[,:]', s)],
'junit_xml': str,
}

Expand Down
1 change: 1 addition & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self) -> None:
self.platform = sys.platform
self.custom_typing_module = None # type: Optional[str]
self.custom_typeshed_dir = None # type: Optional[str]
self.mypy_path = [] # type: List[str]
self.report_dirs = {} # type: Dict[str, str]
self.silent_imports = False
self.almost_silent = False
Expand Down
25 changes: 25 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,28 @@ def untyped_function():
</package>
</packages>
</coverage>

[case testConfigMypyPath]
# cmd: mypy file.py
[file mypy.ini]
[[mypy]
mypy_path =
foo:bar
, baz
[file foo/foo.pyi]
def foo(x: int) -> str: ...
[file bar/bar.pyi]
def bar(x: str) -> list: ...
[file baz/baz.pyi]
def baz(x: list) -> dict: ...
[file file.py]
import no_stubs
from foo import foo
from bar import bar
from baz import baz
baz(bar(foo(42)))
baz(bar(foo('oof')))
[out]
file.py:1: error: Cannot find module named 'no_stubs'
file.py:1: note: (Perhaps setting MYPYPATH or using the "--silent-imports" flag would help)
file.py:6: error: Argument 1 to "foo" has incompatible type "str"; expected "int"