Skip to content

[WIP] Begin implementing PEP 561 checking #4278

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
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
15 changes: 15 additions & 0 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,21 @@ def find() -> Optional[str]:
dir = os.path.normpath(os.path.join(pathitem, dir_chain))
if os.path.isdir(dir):
dirs.append(dir)
try:
user_dir = site.getusersitepackages()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this use the site packages of the mypy installation, not that of the code being typechecked?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I need to add that. Thanks for the reminder!

package_dirs = site.getsitepackages() + [user_dir]
except AttributeError:
package_dirs = [get_python_lib()]

for pkg_dir in package_dirs:
# Third-party stub packages
stub_pkg = os.path.join(pkg_dir, components[0] + '_stubs')
if os.path.isfile(os.path.join(stub_pkg, 'py.typed')):
components[0] = components[0] + '_stubs'
dirs.append(os.path.join(pkg_dir, os.sep.join(components[:-1])))
elif os.path.isfile(os.path.join(pkg_dir, components[0], 'py.typed')):
dirs.append(os.path.join(pkg_dir, dir_chain))

find_module_dir_cache[dir_chain, lib_path] = dirs
candidate_base_dirs = find_module_dir_cache[dir_chain, lib_path]

Expand Down