-
Notifications
You must be signed in to change notification settings - Fork 2k
UP018 should detect more unnecessarily wrapped literals #19864
Copy link
Copy link
Closed
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Summary
Some unnecessarily wrapped literals would be easy for native-literals (UP018) to detect but are not detected.
int() is not detected when followed by an attribute. This is to avoid a syntax error. However, the syntax error can be avoided with parentheses. Compare int(0), which UP018 always detects, inserting parentheses when needed.
Implicitly concatenated string literals are skipped for no apparent reason. If it spans multiple lines, it still needs to be parenthesized, but the str call is unnecessary.
The object keyword of str is not supported.
complex is not supported.
$ cat >up018.py <<'# EOF'
int().denominator
str("A" "B")
str(
"A"
"B"
)
str(object="!")
complex(1j)
complex(real=1j)
# EOF
$ ruff --isolated check up018.py --select UP018
All checks passed!Ideal fixed output:
(0).denominator
"A" "B"
(
"A"
"B"
)
"!"
1j
1jVersion
ruff 0.12.8 (f51a228 2025-08-07)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule