Skip to content

Commit 2f338ce

Browse files
authored
Further improve mypy_test.py (#7484)
* Run mypy on the 3.11 stdlib in CI, as a regression test for python/mypy#12220 * Correct the docstring at the top of the file following the changes made in #7478 * Stop the test from crashing when run locally if there's an extra file/folder in the stubs directory.
1 parent fa33222 commit 2f338ce

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
strategy:
5656
matrix:
5757
platform: ["linux", "win32", "darwin"]
58-
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10"]
58+
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
5959
fail-fast: false
6060
steps:
6161
- uses: actions/checkout@v2

tests/mypy_test.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
88
1. Parse sys.argv
99
2. Compute appropriate arguments for mypy
10-
3. Stuff those arguments into sys.argv
11-
4. Run mypy.main('')
12-
5. Repeat steps 2-4 for other mypy runs (e.g. --py2)
10+
3. Pass those arguments to mypy.api.run()
1311
"""
1412

1513
import argparse
@@ -95,15 +93,13 @@ def parse_version(v_str):
9593
return int(m.group(1)), int(m.group(2))
9694

9795

98-
def is_supported(distribution, major):
99-
dist_path = Path("stubs", distribution)
100-
with open(dist_path / "METADATA.toml") as f:
101-
data = dict(tomli.loads(f.read()))
96+
def is_supported(distribution_path: Path, major: int) -> bool:
97+
data = dict(tomli.loads((distribution_path / "METADATA.toml").read_text()))
10298
if major == 2:
10399
# Python 2 is not supported by default.
104100
return bool(data.get("python2", False))
105101
# Python 3 is supported by default.
106-
return has_py3_stubs(dist_path)
102+
return has_py3_stubs(distribution_path)
107103

108104

109105
# Keep this in sync with stubtest_third_party.py
@@ -278,10 +274,15 @@ def test_third_party_distribution(distribution: str, major: int, minor: int, arg
278274
return code, len(files)
279275

280276

277+
def is_probably_stubs_folder(distribution: str, distribution_path: Path) -> bool:
278+
"""Validate that `dist_path` is a folder containing stubs"""
279+
return distribution != ".mypy_cache" and distribution_path.is_dir()
280+
281+
281282
def main():
282283
args = parser.parse_args()
283284

284-
versions = [(3, 10), (3, 9), (3, 8), (3, 7), (3, 6), (2, 7)]
285+
versions = [(3, 11), (3, 10), (3, 9), (3, 8), (3, 7), (3, 6), (2, 7)]
285286
if args.python_version:
286287
versions = [v for v in versions if any(("%d.%d" % v).startswith(av) for av in args.python_version)]
287288
if not versions:
@@ -327,7 +328,12 @@ def main():
327328
if distribution == "SQLAlchemy":
328329
continue # Crashes
329330

330-
if not is_supported(distribution, major):
331+
distribution_path = Path("stubs", distribution)
332+
333+
if not is_probably_stubs_folder(distribution, distribution_path):
334+
continue
335+
336+
if not is_supported(distribution_path, major):
331337
continue
332338

333339
this_code, checked = test_third_party_distribution(distribution, major, minor, args)

0 commit comments

Comments
 (0)