-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Enable Ruff flake8-use-pathlib (PTH) #13795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
srittau
merged 29 commits into
python:main
from
Avasam:Enable-Ruff-flake8-use-pathlib-(PTH)
May 5, 2025
Merged
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
cdfe65a
Enable Ruff flake8-use-pathlib (PTH)
Avasam e9338bd
Merge branch 'main' of https://github.com/python/typeshed into Enable…
Avasam afb28a5
Get name from Path for distribution
Avasam 4cc9af4
More iterdir
Avasam 0e70eb7
Revert Path.walk. That was added in 3.12
Avasam fc578a0
Use asposix for slash normalization
Avasam 792b1fa
Replace .read and .write on Path
Avasam 5cc0a7e
Merge branch 'main' into Enable-Ruff-flake8-use-pathlib-(PTH)
Avasam 6b8c992
Update some Path instanciation
Avasam fe093d1
Merge branch 'Enable-Ruff-flake8-use-pathlib-(PTH)' of https://github…
Avasam 73721d1
Merge branch 'main' into Enable-Ruff-flake8-use-pathlib-(PTH)
Avasam 1be376a
Merge branch 'main' of https://github.com/python/typeshed into Enable…
Avasam 6108b58
Update _get_relative
Avasam 5ae7dd4
Fix file exclusion from relative path
Avasam a959eb8
Finished fixing pytype exclusion list
Avasam 3d0fd80
Revert most os-listdir (PTH208)
Avasam adca01a
Wrap another filename in Path for consistency
Avasam 708b161
Fix mypy not able to infer list type in script
Avasam 6f5a72b
Merge branch 'main' into Enable-Ruff-flake8-use-pathlib-(PTH)
srittau 4fe6987
Merge branch 'main' into Enable-Ruff-flake8-use-pathlib-(PTH)
Avasam 326ad59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5f0219b
Go back to string manip, but with clearer names
Avasam 0de18b5
These Sequences can be Iterables
Avasam 0240a2d
Merge branch 'Enable-Ruff-flake8-use-pathlib-(PTH)' of https://github…
Avasam 1b3a3a0
Merge branch 'main' of https://github.com/python/typeshed into Enable…
Avasam c1f405d
Use removesuffix instead of rsplit
Avasam 63739d0
Further simplify _get_relative after merge
Avasam f3a9ff4
Merge branch 'Enable-Ruff-flake8-use-pathlib-(PTH)' of https://github…
Avasam 9548b51
Strip newline from line
Avasam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,8 @@ def match(path: Path, args: TestConfig) -> bool: | |
|
|
||
| def add_files(files: list[Path], module: Path, args: TestConfig) -> None: | ||
| """Add all files in package or module represented by 'name' located in 'root'.""" | ||
| if module.name.startswith("."): | ||
| return | ||
| if module.is_file() and module.suffix == ".pyi": | ||
| if match(module, args): | ||
| files.append(module) | ||
|
|
@@ -244,10 +246,8 @@ def add_third_party_files(distribution: str, files: list[Path], args: TestConfig | |
| seen_dists.add(distribution) | ||
| seen_dists.update(r.name for r in typeshed_reqs) | ||
| root = distribution_path(distribution) | ||
| for name in os.listdir(root): | ||
| if name.startswith("."): | ||
| continue | ||
| add_files(files, (root / name), args) | ||
| for path in root.iterdir(): | ||
| add_files(files, path, args) | ||
|
|
||
|
|
||
| class TestResult(NamedTuple): | ||
|
|
@@ -295,7 +295,7 @@ def test_third_party_distribution( | |
| def test_stdlib(args: TestConfig) -> TestResult: | ||
| files: list[Path] = [] | ||
| for file in STDLIB_PATH.iterdir(): | ||
| if file.name in ("VERSIONS", TESTS_DIR) or file.name.startswith("."): | ||
| if file.name in ("VERSIONS", TESTS_DIR): | ||
| continue | ||
| add_files(files, file, args) | ||
|
|
||
|
|
@@ -472,7 +472,7 @@ def test_third_party_stubs(args: TestConfig, tempdir: Path) -> TestSummary: | |
| gitignore_spec = get_gitignore_spec() | ||
| distributions_to_check: dict[str, PackageDependencies] = {} | ||
|
|
||
| for distribution in sorted(os.listdir("stubs")): | ||
| for distribution in sorted([distribution.name for distribution in STUBS_PATH.iterdir()]): | ||
|
||
| dist_path = distribution_path(distribution) | ||
|
|
||
| if spec_matches_path(gitignore_spec, dist_path): | ||
|
|
@@ -525,15 +525,14 @@ def test_third_party_stubs(args: TestConfig, tempdir: Path) -> TestSummary: | |
|
|
||
| def test_typeshed(args: TestConfig, tempdir: Path) -> TestSummary: | ||
| print(f"*** Testing Python {args.version} on {args.platform}") | ||
| stdlib_dir, stubs_dir = Path("stdlib"), Path("stubs") | ||
| summary = TestSummary() | ||
|
|
||
| if stdlib_dir in args.filter or any(stdlib_dir in path.parents for path in args.filter): | ||
| if STDLIB_PATH in args.filter or any(STDLIB_PATH in path.parents for path in args.filter): | ||
| mypy_result, files_checked = test_stdlib(args) | ||
| summary.register_result(mypy_result, files_checked) | ||
| print() | ||
|
|
||
| if stubs_dir in args.filter or any(stubs_dir in path.parents for path in args.filter): | ||
| if STUBS_PATH in args.filter or any(STUBS_PATH in path.parents for path in args.filter): | ||
| tp_results = test_third_party_stubs(args, tempdir) | ||
| summary.merge(tp_results) | ||
| print() | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a straight up downgrade.
os-listdir (PTH208)
Only one other change of
os.listdir-->Path.iterdirseems like an actual improvement. (intests/mypy_test.py)