Skip to content

Respect the semantics of EXPLICIT #10780

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions docs/source/running_mypy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ How mypy determines fully qualified module names depends on if the options

With :option:`--explicit-package-bases <mypy --explicit-package-bases>`, mypy
will locate the nearest parent directory that is a member of the ``MYPYPATH``
environment variable, the :confval:`mypy_path` config or is the current
working directory. Mypy will then use the relative path to determine the
fully qualified module name.
environment variable, the :confval:`mypy_path` config or, if neither of those
configuration options are specified, then the current working directory.
Mypy will then use the relative path to determine the fully qualified module name.

For example, say your directory tree consists solely of
``src/namespace_pkg/mod.py``. If you run the command following command, mypy
Expand Down
4 changes: 2 additions & 2 deletions mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def normalise_package_base(root: str) -> str:
def get_explicit_package_bases(options: Options) -> Optional[List[str]]:
"""Returns explicit package bases to use if the option is enabled, or None if disabled.

We currently use MYPYPATH and the current directory as the package bases. In the future,
We currently use MYPYPATH or the current directory as the package bases. In the future,
when --namespace-packages is the default could also use the values passed with the
--package-root flag, see #9632.

Expand All @@ -82,7 +82,7 @@ def get_explicit_package_bases(options: Options) -> Optional[List[str]]:
"""
if not options.explicit_package_bases:
return None
roots = mypy_path() + options.mypy_path + [os.getcwd()]
roots = mypy_path() + options.mypy_path or [os.getcwd()]
return [normalise_package_base(root) for root in roots]


Expand Down
5 changes: 3 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
try:
# Keep a dummy reference (res) for memory profiling afterwards, as otherwise
# the result could be freed.
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
alt_lib_path = "" if options.explicit_package_bases else None
res = build.build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
except CompileError as e:
blockers = True
if not e.use_stdout:
Expand Down Expand Up @@ -862,7 +863,7 @@ def add_invertible_flag(flag: str,
"mypy.readthedocs.io/en/stable/running_mypy.html#running-mypy")
add_invertible_flag(
'--explicit-package-bases', default=False,
help="Use current directory and MYPYPATH to determine module names of files passed",
help="Use current directory or MYPYPATH to determine module names of files passed",
group=code_group)
code_group.add_argument(
"--exclude",
Expand Down
2 changes: 1 addition & 1 deletion mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def compute_search_paths(sources: List[BuildSource],
# alt_lib_path is used by some tests to bypass the normal lib_path mechanics.
# If we don't have one, grab directories of source files.
python_path: List[str] = []
if not alt_lib_path:
if alt_lib_path is None:
for source in sources:
# Include directory of the program file in the module search path.
if source.base_dir:
Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self) -> None:
# multiple directories. This flag affects both import discovery and the association of
# input files/modules/packages to the relevant file and fully qualified module name.
self.namespace_packages = False
# Use current directory and MYPYPATH to determine fully qualified module names of files
# Use current directory or MYPYPATH to determine fully qualified module names of files
# passed by automatically considering their subdirectories as packages. This is only
# relevant if namespace packages are enabled, since otherwise examining __init__.py's is
# sufficient to determine module names for files. As a possible alternative, add a single
Expand Down