Skip to content

[flake8-use-pathlib] autofix and new rules#2348

Closed
sbrugman wants to merge 2 commits intoastral-sh:mainfrom
sbrugman:pathlib-extension
Closed

[flake8-use-pathlib] autofix and new rules#2348
sbrugman wants to merge 2 commits intoastral-sh:mainfrom
sbrugman:pathlib-extension

Conversation

@sbrugman
Copy link
Contributor

@sbrugman sbrugman commented Jan 30, 2023

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 constructor Path(".") to Path()
  • Replace os.path.getsize with Path.stat()
  • Using PTH2XX rather than FURBXXX (rules originate from refurb) to keep all pathlib logic together

Autofix for:

  • PTH201: Path(".") to Path()
  • PTH109: os.path.getcwd(x) to Path(x).cwd()

Nested calls are unwrapped:

  • Path(os.path.getcwd(x)) => Path(x).cwd()

Promote get_member_import_name_alias from pylint to ast.helpers

Follow-up work items:

@sbrugman sbrugman force-pushed the pathlib-extension branch 2 times, most recently from 0a47e2c to 9655360 Compare January 30, 2023 12:30
@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Feb 10, 2023
@sbrugman sbrugman marked this pull request as draft February 11, 2023 10:11
@sbrugman sbrugman changed the title flake8-use-pathlib autofix and new rules [flake8-use-pathlib] autofix and new rules Feb 11, 2023
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`
@charliermarsh
Copy link
Member

We should finally be able to support this once #3787 lands.

@aqeelat
Copy link

aqeelat commented Jun 6, 2023

@sbrugman just to remind you that #3787 was merged and I think you can get the ball rolling again on this PR.

@sbrugman
Copy link
Contributor Author

sbrugman commented Jun 6, 2023

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.

@aqeelat
Copy link

aqeelat commented Jun 26, 2023

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.

charliermarsh pushed a commit that referenced this pull request Jul 20, 2023
…(`PTH201`) (#5833)

Reviving #2348 step by step

Pt 2. PTH201: Path Constructor Default Argument

- rule originates from `refurb`:
#1348
- Using PTH201 rather than FURBXXX to keep all pathlib logic together
charliermarsh pushed a commit that referenced this pull request Jul 20, 2023
…|m|c)-time` (`PTH202-205`) (#5835)

Reviving #2348 step by step

Pt 3. implement detection for:
- `os.path.getsize`
- `os.path.getmtime`
- `os.path.getctime`
- `os.path.getatime`
charliermarsh pushed a commit that referenced this pull request Jul 21, 2023
Reviving #2348 step by step

Pt 1: docs

Tracking issue: #2646.
@charliermarsh
Copy link
Member

@sbrugman - Should we close this out given that it's being ported over in chunks to new PRs?

@sbrugman sbrugman closed this Jul 21, 2023
@sbrugman sbrugman deleted the pathlib-extension branch December 10, 2023 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants