-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[flake8-use-pathlib
] add autofix for PTH202
#18763
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
this not the final version yet, and i still have some questions |
should we remove [ import os
x = os.path.getsize(filename="filename")
y = os.path.getsize(filename=b"filename")
z = os.path.getsize(filename=__file__) => import os # unused
from pathlib import Path # we also have to import it if it wasn't there before
x = Path("filename").stat().st_size
y = Path(b"filename").stat().st_size
z = Path(__file__).stat().st_size |
I don't think you need to remove the imports, you can defer to unused-import (F401) for that, but you do need to add the Let me know if you have more questions or when it's ready for review! |
as well as, for example os.path.getsize(Path("filename")) => Path(Path("filename")).stat().st_size |
The call to Path with parentheses here seems redundant, but I don't think we can consider it unnecessary since it might have additional methods like |
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PTH202 | 10 | 10 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+10 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)
apache/airflow (+4 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ airflow-core/tests/unit/utils/test_log_handlers.py:375:29: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + airflow-core/tests/unit/utils/test_log_handlers.py:376:30: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + dev/breeze/src/airflow_breeze/utils/parallel.py:308:24: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + providers/amazon/src/airflow/providers/amazon/aws/transfers/dynamodb_to_s3.py:244:16: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size`
zulip/zulip (+6 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ scripts/setup/generate_secrets.py:65:47: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + tools/lib/test_server.py:64:45: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + zerver/data_import/mattermost.py:361:21: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + zerver/data_import/slack.py:1537:70: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + zerver/lib/export.py:2955:41: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size` + zerver/lib/upload/local.py:110:45: PTH202 [*] `os.path.getsize` should be replaced by `Path.stat().st_size`
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PTH202 | 10 | 10 | 0 | 0 | 0 |
is it worth splitting pr if the changes are the same as this pr? the question is more to this one |
Summary
/closes #2331
Test Plan
update snapshots