Skip to content

Make sure we use VERSIONS file in typeshed, refs #12062 #12066

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
25 changes: 22 additions & 3 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,20 @@ def get_stub(module: str) -> Optional[nodes.MypyFile]:
return _all_stubs.get(module)


def _is_allowed_module_version(
version_info: Tuple[int, int],
versions: Optional[Tuple[Tuple[int, int], Optional[Tuple[int, int]]]],
) -> bool:
if versions is None:
return True

minver, maxver = versions
return (
version_info >= minver
and (maxver is None or version_info <= maxver)
)


def get_typeshed_stdlib_modules(custom_typeshed_dir: Optional[str]) -> List[str]:
"""Returns a list of stdlib modules in typeshed (for current Python version)."""
stdlib_py_versions = mypy.modulefinder.load_stdlib_py_versions(custom_typeshed_dir)
Expand All @@ -1117,8 +1131,7 @@ def get_typeshed_stdlib_modules(custom_typeshed_dir: Optional[str]) -> List[str]
else:
version_info = sys.version_info[0:2]
for module, versions in stdlib_py_versions.items():
minver, maxver = versions
if version_info >= minver and (maxver is None or version_info <= maxver):
if _is_allowed_module_version(version_info, versions):
packages.add(module)

if custom_typeshed_dir:
Expand All @@ -1132,7 +1145,13 @@ def get_typeshed_stdlib_modules(custom_typeshed_dir: Optional[str]) -> List[str]
if path.stem == "__init__":
path = path.parent
module = ".".join(path.relative_to(stdlib_dir).parts[:-1] + (path.stem,))
if module.split(".")[0] in packages:
if (
module.split(".")[0] in packages
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is now a bit suspect to me:

  • It only checks the top-level name of the package.
  • And it shouldn't be necessary, since the package name doesn't get added to packages if the module is not supported, due to the check above.

and _is_allowed_module_version(
version_info,
stdlib_py_versions.get(module),
)
):
modules.append(module)
return sorted(modules)

Expand Down