-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[flake8-use-pathlib
] autofix and new rules
#2348
Conversation
0a47e2c
to
9655360
Compare
9655360
to
6d0df09
Compare
6d0df09
to
3a0ad10
Compare
3a0ad10
to
2345acb
Compare
flake8-use-pathlib
] autofix and new rules
2345acb
to
7325334
Compare
PTH200-204: - Simplify path constructor `Path(".")` to `Path()` - Replace `os.path.getsize` with `Path.stat()` Autofix for: - PTH200: `Path(".")` to `Path()` - PTH109: `os.path.getcwd(x)` to `Path(x).cwd()` Promote `get_member_import_name_alias` from `pylint` to `ast.helpers`
7325334
to
69884b3
Compare
bdc347e
to
e8285f8
Compare
We should finally be able to support this once #3787 lands. |
Anyone interested, feel free to pick up where this PR left off (@aqeelat perhaps?). I'd like to work on it, but do not expect it to fit soon. |
I honestly have 0 rust experience and I'm not comfortable taking over. |
@sbrugman - Should we close this out given that it's being ported over in chunks to new PRs? |
See also #2331 and #2090
Kick-off pathlib autofix. The others could mostly be implemented in the same logic, but perhaps good to test with only this small subset to see what occurs in the wild.
PTH201-205:
Simplify path constructorPath(".")
toPath()
Replaceos.path.getsize
withPath.stat()
Using PTH2XX rather than FURBXXX (rules originate fromrefurb
) to keep allpathlib
logic togetherAutofix for:
PTH201:Path(".")
toPath()
os.path.getcwd(x)
toPath(x).cwd()
Nested calls are unwrapped:
Path(os.path.getcwd(x))
=>Path(x).cwd()
Promote
get_member_import_name_alias
frompylint
toast.helpers
Follow-up work items:
from pathlib import Path
) or remove (os
/os.path
) imports (tracked by Add the possibility to add import and respect the import sorting. #835)os.path.stats
is notint
(open file descriptors are not supported in the pathlib version). My guess is that this feature is probably not widely used, and people could useos.path.lstat
to prevent lints (next to #noqa).Naming convention: rename from pathlib-* to os(-path)-*