Skip to content

Commit c17196f

Browse files
authored
Merge branch 'main' into issue-9607
2 parents 6b3ab4f + 7fdd050 commit c17196f

5 files changed

Lines changed: 20 additions & 16 deletions

File tree

.github/workflows/typecheck_typeshed_code.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- uses: actions/checkout@v3
5252
- uses: actions/setup-python@v4
5353
with:
54-
python-version: "3.9"
54+
python-version: "3.10"
5555
cache: pip
5656
cache-dependency-path: requirements-tests.txt
5757
- run: pip install -r requirements-tests.txt
@@ -66,5 +66,5 @@ jobs:
6666
with:
6767
version: ${{ steps.pyright_version.outputs.value }}
6868
python-platform: ${{ matrix.python-platform }}
69-
python-version: "3.9"
69+
python-version: "3.10"
7070
project: ./pyrightconfig.scripts_and_tests.json

requirements-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ typing-extensions==4.6.3
2525

2626
# Type stubs used to type check our scripts.
2727
types-pyyaml>=6.0.12.7
28-
types-setuptools>=67.5.0.0

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ objects at runtime.
1919
in the `tests` and `scripts` directories.
2020

2121
To run the tests, follow the [setup instructions](../CONTRIBUTING.md#preparing-the-environment)
22-
in the `CONTRIBUTING.md` document. In particular, you have to run with Python 3.9+.
22+
in the `CONTRIBUTING.md` document. In particular, you have to run with Python 3.10+.
2323

2424
In order for `pytype_test` and `pyright_test` to work correctly, some third-party stubs
2525
may require extra dependencies external to typeshed to be installed in your virtual environment
@@ -72,7 +72,7 @@ for this script.
7272

7373
Note: this test cannot be run on Windows
7474
systems unless you are using Windows Subsystem for Linux.
75-
It also requires a Python version < 3.11 as pytype does not yet support
75+
It can currently only be run on Python 3.10 as pytype does not yet support
7676
Python 3.11 and above.
7777

7878
Run using:

tests/pytype_test.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
from __future__ import annotations
1616

1717
import argparse
18+
import importlib.metadata
1819
import os
1920
import sys
2021
import traceback
22+
from collections import defaultdict
2123
from collections.abc import Iterable, Sequence
2224

23-
import pkg_resources
25+
from packaging.requirements import Requirement
2426

2527
from parse_metadata import read_dependencies
2628

2729
if sys.platform == "win32":
2830
print("pytype does not support Windows.", file=sys.stderr)
2931
sys.exit(1)
30-
if sys.version_info >= (3, 11):
31-
print("pytype does not support Python 3.11+ yet.", file=sys.stderr)
32+
if sys.version_info[:2] != (3, 10):
33+
print("pytype_test.py can currently only be run on Python 3.10.", file=sys.stderr)
3234
sys.exit(1)
3335

3436
# pytype is not py.typed https://github.com/google/pytype/issues/1325
@@ -165,15 +167,18 @@ def get_missing_modules(files_to_test: Sequence[str]) -> Iterable[str]:
165167
except ValueError:
166168
continue
167169
stub_distributions.add(parts[idx + 1])
170+
171+
dist_to_pkg_map = defaultdict(list)
172+
for dist, pkg_list in importlib.metadata.packages_distributions().items():
173+
for pkg in pkg_list:
174+
dist_to_pkg_map[pkg].append(dist)
175+
168176
missing_modules = set()
169177
for distribution in stub_distributions:
170-
for pkg in read_dependencies(distribution).external_pkgs:
171-
egg_info = pkg_resources.get_distribution(pkg).egg_info
172-
assert isinstance(egg_info, str)
173-
# See https://stackoverflow.com/a/54853084
174-
top_level_file = os.path.join(egg_info, "top_level.txt")
175-
with open(top_level_file) as f:
176-
missing_modules.update(f.read().splitlines())
178+
for external_req in read_dependencies(distribution).external_pkgs:
179+
pkg = Requirement(external_req).name
180+
missing_modules.update(dist_to_pkg_map[pkg])
181+
177182
test_dir = os.path.dirname(__file__)
178183
exclude_list = os.path.join(test_dir, "pytype_exclude_list.txt")
179184
with open(exclude_list) as f:

tests/typecheck_typeshed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ReturnCode: TypeAlias = int
1414

1515
SUPPORTED_PLATFORMS = ("linux", "darwin", "win32")
16-
SUPPORTED_VERSIONS = ("3.12", "3.11", "3.10", "3.9")
16+
SUPPORTED_VERSIONS = ("3.12", "3.11", "3.10")
1717
LOWEST_SUPPORTED_VERSION = min(SUPPORTED_VERSIONS, key=lambda x: int(x.split(".")[1]))
1818
DIRECTORIES_TO_TEST = ("scripts", "tests")
1919
EMPTY: list[str] = []

0 commit comments

Comments
 (0)