Skip to content

Commit 0c45df1

Browse files
authored
Check pyrightconfig stricter exclude list order (#15243)
1 parent 6731a33 commit 0c45df1

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

lib/ts_utils/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ def strip_comments(text: str) -> str:
3535
return text.split("#")[0].strip()
3636

3737

38+
def json5_to_json(text: str) -> str:
39+
"""Incomplete conversion from JSON5-like input to valid JSON."""
40+
# Remove full-line // comments only
41+
# (Can not remove inline comments)
42+
text = re.sub(r"(?m)^\s*//.*\n?", "", text)
43+
# Remove trailing commas before } or ]
44+
text = re.sub(r",\s*([}\]])", r"\1", text)
45+
return text
46+
47+
3848
# ====================================================================
3949
# Printing utilities
4050
# ====================================================================

pyrightconfig.stricter.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
// test cases use a custom pyrightconfig file
1010
"**/@tests/test_cases",
1111
"stdlib/__main__.pyi",
12+
"stdlib/_tkinter.pyi",
1213
"stdlib/distutils/cmd.pyi",
1314
"stdlib/distutils/command",
1415
"stdlib/distutils/dist.pyi",
1516
"stdlib/encodings/__init__.pyi",
1617
"stdlib/lib2to3/fixes/*.pyi",
1718
"stdlib/numbers.pyi",
18-
"stdlib/_tkinter.pyi",
1919
"stdlib/tkinter/__init__.pyi",
20-
"stdlib/tkinter/filedialog.pyi",
2120
"stdlib/tkinter/dialog.pyi",
21+
"stdlib/tkinter/filedialog.pyi",
2222
"stdlib/tkinter/scrolledtext.pyi",
2323
"stdlib/tkinter/tix.pyi",
2424
"stdlib/tkinter/ttk.pyi",

tests/check_typeshed_structure.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
from __future__ import annotations
99

10+
import json
1011
import os
1112
import re
1213
from pathlib import Path
1314

1415
from ts_utils.metadata import read_metadata
15-
from ts_utils.paths import REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, TESTS_DIR, tests_path
16+
from ts_utils.paths import PYRIGHT_CONFIG, REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, TESTS_DIR, tests_path
1617
from ts_utils.utils import (
1718
get_all_testcase_directories,
1819
get_gitignore_spec,
20+
json5_to_json,
1921
parse_requirements,
2022
parse_stdlib_versions_file,
2123
spec_matches_path,
@@ -173,6 +175,19 @@ def check_requirement_pins() -> None:
173175
assert str(spec).startswith("=="), msg
174176

175177

178+
def check_pyright_exclude_order() -> None:
179+
"""Check that 'exclude' entries in pyrightconfig.stricter.json are sorted alphabetically."""
180+
text = PYRIGHT_CONFIG.read_text(encoding="utf-8")
181+
text = json5_to_json(text)
182+
data = json.loads(text)
183+
exclude: list[str] = data.get("exclude", [])
184+
185+
for i in range(len(exclude) - 1):
186+
assert (
187+
exclude[i].lower() <= exclude[i + 1].lower()
188+
), f"Entry '{exclude[i]}' should come before '{exclude[i + 1]}' in the {PYRIGHT_CONFIG.name} exclude list"
189+
190+
176191
if __name__ == "__main__":
177192
check_versions_file()
178193
check_metadata()
@@ -182,3 +197,4 @@ def check_requirement_pins() -> None:
182197
check_stubs()
183198
check_distutils()
184199
check_test_cases()
200+
check_pyright_exclude_order()

0 commit comments

Comments
 (0)