Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
// test cases use a custom pyrightconfig file
"**/@tests/test_cases",
"stdlib/__main__.pyi",
"stdlib/_tkinter.pyi",
"stdlib/distutils/cmd.pyi",
"stdlib/distutils/command",
"stdlib/distutils/dist.pyi",
"stdlib/encodings/__init__.pyi",
"stdlib/lib2to3/fixes/*.pyi",
"stdlib/numbers.pyi",
"stdlib/_tkinter.pyi",
"stdlib/tkinter/__init__.pyi",
"stdlib/tkinter/filedialog.pyi",
"stdlib/tkinter/dialog.pyi",
"stdlib/tkinter/filedialog.pyi",
"stdlib/tkinter/scrolledtext.pyi",
"stdlib/tkinter/tix.pyi",
"stdlib/tkinter/ttk.pyi",
Expand Down
23 changes: 22 additions & 1 deletion tests/check_typeshed_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

from __future__ import annotations

import json
import os
import re
from pathlib import Path

from ts_utils.metadata import read_metadata
from ts_utils.paths import REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, TESTS_DIR, tests_path
from ts_utils.paths import PYRIGHT_CONFIG, REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, TESTS_DIR, tests_path
from ts_utils.utils import (
get_all_testcase_directories,
get_gitignore_spec,
Expand Down Expand Up @@ -173,6 +174,25 @@ def check_requirement_pins() -> None:
assert str(spec).startswith("=="), msg


def check_pyright_exclude_order() -> None:
"""Check that 'exclude' entries in pyrightconfig.stricter.json are sorted alphabetically."""
text = PYRIGHT_CONFIG.read_text(encoding="utf-8")

# Remove full-line // comments only
# (Can not remove inline comments)
text = re.sub(r"(?m)^\s*//.*\n?", "", text)
# Remove trailing commas before } or ]
text = re.sub(r",\s*([}\]])", r"\1", text)

data = json.loads(text)
exclude: list[str] = data.get("exclude", [])

for i in range(len(exclude) - 1):
assert (
exclude[i].lower() <= exclude[i + 1].lower()
), f"Entry '{exclude[i]}' should come before '{exclude[i + 1]}' in the {PYRIGHT_CONFIG.name} exclude list"


if __name__ == "__main__":
check_versions_file()
check_metadata()
Expand All @@ -182,3 +202,4 @@ def check_requirement_pins() -> None:
check_stubs()
check_distutils()
check_test_cases()
check_pyright_exclude_order()