Skip to content

Commit 6078927

Browse files
AlexWaygoodAvasam
andauthored
Improve pyright verification of third-party test cases in CI (#9650)
Co-authored-by: Avasam <[email protected]>
1 parent 565a1a0 commit 6078927

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,29 @@ jobs:
140140
with:
141141
file: "pyproject.toml"
142142
field: "tool.typeshed.pyright_version"
143-
- uses: jakebailey/pyright-action@v1
143+
- name: Run pyright with basic settings on all the stubs
144+
uses: jakebailey/pyright-action@v1
144145
with:
145146
version: ${{ steps.pyright_version.outputs.value }}
146147
python-platform: ${{ matrix.python-platform }}
147148
python-version: ${{ matrix.python-version }}
148149
no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
149-
project: ./pyrightconfig.stricter.json
150-
- uses: jakebailey/pyright-action@v1
150+
- name: Run pyright with stricter settings on some of the stubs
151+
uses: jakebailey/pyright-action@v1
151152
with:
152153
version: ${{ steps.pyright_version.outputs.value }}
153154
python-platform: ${{ matrix.python-platform }}
154155
python-version: ${{ matrix.python-version }}
155156
no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
156-
project: ./pyrightconfig.testcases.json
157-
- uses: jakebailey/pyright-action@v1
157+
project: ./pyrightconfig.stricter.json
158+
- name: Run pyright on the test cases
159+
uses: jakebailey/pyright-action@v1
158160
with:
159161
version: ${{ steps.pyright_version.outputs.value }}
160162
python-platform: ${{ matrix.python-platform }}
161163
python-version: ${{ matrix.python-version }}
162164
no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
165+
project: ./pyrightconfig.testcases.json
163166

164167
stub-uploader:
165168
name: Run the stub_uploader tests

pyrightconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"stdlib",
66
"stubs",
77
],
8+
"exclude": [
9+
// test cases use a custom config file
10+
"stubs/**/@tests/test_cases"
11+
],
812
"typeCheckingMode": "basic",
913
"strictListInference": true,
1014
"strictDictionaryInference": true,

pyrightconfig.stricter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"stubs",
77
],
88
"exclude": [
9+
// test cases use a custom pyrightconfig file
10+
"stubs/**/@tests/test_cases",
911
"stdlib/distutils/command",
1012
"stdlib/lib2to3/refactor.pyi",
1113
"stdlib/_tkinter.pyi",

pyrightconfig.testcases.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"typeshedPath": ".",
44
"include": [
55
"test_cases",
6+
"stubs/**/@tests/test_cases"
67
],
78
"typeCheckingMode": "strict",
89
// Using unspecific "type ignore" comments in test_cases.

stubs/invoke/@tests/test_cases/check_task.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
21
from __future__ import annotations
32

43
from invoke import Context, task

stubs/protobuf/@tests/test_cases/check_struct.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
21
from __future__ import annotations
32

43
from google.protobuf.struct_pb2 import ListValue, Struct

stubs/regex/@tests/test_cases/check_finditer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
2-
31
from __future__ import annotations
42

53
from typing import List

stubs/requests/@tests/test_cases/check_post.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
2-
31
from __future__ import annotations
42

53
from collections.abc import Iterable

tests/check_consistent.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,22 @@ def check_stubs() -> None:
6565
allowed = {"METADATA.toml", "README", "README.md", "README.rst", "@tests"}
6666
assert_consistent_filetypes(dist, kind=".pyi", allowed=allowed)
6767

68+
tests_dir = dist / "@tests"
69+
if tests_dir.exists() and tests_dir.is_dir():
70+
py_files_present = any(file.suffix == ".py" for file in tests_dir.iterdir())
71+
error_message = "Test-case files must be in an `@tests/test_cases/` directory, not in the `@tests/` directory"
72+
assert not py_files_present, error_message
73+
6874

6975
def check_test_cases() -> None:
70-
for package_name, testcase_dir in get_all_testcase_directories():
76+
for _, testcase_dir in get_all_testcase_directories():
7177
assert_consistent_filetypes(testcase_dir, kind=".py", allowed={"README.md"}, allow_nonidentifier_filenames=True)
7278
bad_test_case_filename = 'Files in a `test_cases` directory must have names starting with "check_"; got "{}"'
7379
for file in testcase_dir.rglob("*.py"):
7480
assert file.stem.startswith("check_"), bad_test_case_filename.format(file)
7581
with open(file, encoding="UTF-8") as f:
7682
lines = {line.strip() for line in f}
7783
assert "from __future__ import annotations" in lines, "Test-case files should use modern typing syntax where possible"
78-
if package_name != "stdlib":
79-
pyright_setting_not_enabled_msg = (
80-
f'Third-party test-case file "{file}" must have '
81-
f'"# pyright: reportUnnecessaryTypeIgnoreComment=true" '
82-
f"at the top of the file"
83-
)
84-
has_pyright_setting_enabled = "# pyright: reportUnnecessaryTypeIgnoreComment=true" in lines
85-
assert has_pyright_setting_enabled, pyright_setting_not_enabled_msg
8684

8785

8886
def check_no_symlinks() -> None:

0 commit comments

Comments
 (0)