-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: main
Are you sure you want to change the base?
Conversation
…-Ruff-flake8-use-pathlib-(PTH)
lib/ts_utils/utils.py
Outdated
@@ -203,7 +203,7 @@ def allowlists(distribution_name: str) -> list[str]: | |||
|
|||
@functools.cache | |||
def get_gitignore_spec() -> pathspec.PathSpec: | |||
with open(".gitignore", encoding="UTF-8") as f: | |||
with Path(".gitignore").open(encoding="UTF-8") as f: |
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.
I prefer the simple open()
in this and similar cases. But it's no deal breaker for me. The rest looks good.
….com/Avasam/typeshed into Enable-Ruff-flake8-use-pathlib-(PTH)
…-Ruff-flake8-use-pathlib-(PTH)
lib/ts_utils/requirements.py
Outdated
distributions = os.listdir(STUBS_PATH) | ||
distributions = [distribution.name for distribution in STUBS_PATH.iterdir()] | ||
|
||
return set(itertools.chain.from_iterable([read_dependencies(distribution).external_pkgs for distribution in distributions])) | ||
|
||
|
||
def get_stubtest_system_requirements(distributions: Iterable[str] = (), platform: str = sys.platform) -> list[str]: | ||
if not distributions: | ||
distributions = os.listdir(STUBS_PATH) | ||
distributions = [distribution.name for distribution in STUBS_PATH.iterdir()] |
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.iterdir
seems like an actual improvement. (in tests/mypy_test.py
)
tests/mypy_test.py
Outdated
@@ -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()]): |
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.iterdir
seems like an actual improvement. (in add_third_party_files
above)
Kept this one for last. Closes #13295
Some rules in this group are forcing some refactoring to use
pathlib
. In some cases, it's a lot cleaner, in others it's debatable.I unconditionally followed all the rules. Please indicate changes you disagree with/preferred in the old style. I'll revert those and disable the relevant rules.
There's also a few
with read
andwith write
that can be further rewritten to be more concise withPath.read_text
andPath.write_text