[flake8-use-pathlib] Catch redundant joins in PTH201 and avoid syntax errors (#15177)

## Summary

Resolves #10453, resolves #15165.

## Test Plan

`cargo nextest run` and `cargo insta test`.
This commit is contained in:
InSync 2024-12-30 10:31:35 +07:00 committed by GitHub
parent d3492178e1
commit 901b7dd8f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 437 additions and 66 deletions

View file

@ -1,15 +1,70 @@
from pathlib import Path, PurePath
from pathlib import Path as pth
# match
_ = Path(".")
_ = pth(".")
_ = PurePath(".")
_ = Path("")
Path('', )
Path(
'',
)
Path( # Comment before argument
'',
)
Path(
'', # EOL comment
)
Path(
'' # Comment in the middle of implicitly concatenated string
".",
)
Path(
'' # Comment before comma
,
)
Path(
'',
) / "bare"
Path( # Comment before argument
'',
) / ("parenthesized")
Path(
'', # EOL comment
) / ( ("double parenthesized" ) )
( Path(
'' # Comment in the middle of implicitly concatenated string
".",
) )/ (("parenthesized path call")
# Comment between closing parentheses
)
Path(
'' # Comment before comma
,
) / "multiple" / (
"frag" # Comment
'ment'
)
# no match
_ = Path()
print(".")
Path("file.txt")
Path(".", "folder")
PurePath(".", "folder")
Path()