mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
[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:
parent
d3492178e1
commit
901b7dd8f8
4 changed files with 437 additions and 66 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue