mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 04:48:07 +00:00
Fix false negatives in Truthiness::from_expr for lambdas, generators, and f-strings (#20704)
This commit is contained in:
parent
f73bb45be6
commit
c69fa75cd5
9 changed files with 285 additions and 4 deletions
|
|
@ -33,3 +33,10 @@ class ShellConfig:
|
|||
|
||||
def run(self, username):
|
||||
Popen("true", shell={**self.shell_defaults, **self.fetch_shell_config(username)})
|
||||
|
||||
# Additional truthiness cases for generator, lambda, and f-strings
|
||||
Popen("true", shell=(i for i in ()))
|
||||
Popen("true", shell=lambda: 0)
|
||||
Popen("true", shell=f"{b''}")
|
||||
x = 1
|
||||
Popen("true", shell=f"{x=}")
|
||||
|
|
|
|||
|
|
@ -6,3 +6,19 @@ foo(shell=True)
|
|||
|
||||
foo(shell={**{}})
|
||||
foo(shell={**{**{}}})
|
||||
|
||||
# Truthy non-bool values for `shell`
|
||||
foo(shell=(i for i in ()))
|
||||
foo(shell=lambda: 0)
|
||||
|
||||
# f-strings guaranteed non-empty
|
||||
foo(shell=f"{b''}")
|
||||
x = 1
|
||||
foo(shell=f"{x=}")
|
||||
|
||||
# Additional truthiness cases for generator, lambda, and f-strings
|
||||
foo(shell=(i for i in ()))
|
||||
foo(shell=lambda: 0)
|
||||
foo(shell=f"{b''}")
|
||||
x = 1
|
||||
foo(shell=f"{x=}")
|
||||
|
|
|
|||
|
|
@ -9,3 +9,10 @@ os.system("tar cf foo.tar bar/*")
|
|||
|
||||
subprocess.Popen(["chmod", "+w", "*.py"], shell={**{}})
|
||||
subprocess.Popen(["chmod", "+w", "*.py"], shell={**{**{}}})
|
||||
|
||||
# Additional truthiness cases for generator, lambda, and f-strings
|
||||
subprocess.Popen("chmod +w foo*", shell=(i for i in ()))
|
||||
subprocess.Popen("chmod +w foo*", shell=lambda: 0)
|
||||
subprocess.Popen("chmod +w foo*", shell=f"{b''}")
|
||||
x = 1
|
||||
subprocess.Popen("chmod +w foo*", shell=f"{x=}")
|
||||
|
|
|
|||
|
|
@ -197,3 +197,10 @@ for x in {**a, **b} or [None]:
|
|||
|
||||
# https://github.com/astral-sh/ruff/issues/7127
|
||||
def f(a: "'b' or 'c'"): ...
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/20703
|
||||
print(f"{b''}" or "bar") # SIM222
|
||||
x = 1
|
||||
print(f"{x=}" or "bar") # SIM222
|
||||
(lambda: 1) or True # SIM222
|
||||
(i for i in range(1)) or "bar" # SIM222
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue