You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With RUF027 enabled, I would expect it to flag both of these, which it currently does not:
function calls within the bracketed expression, like print("Hello {foo()}")
bracketed expressions that access an attribute of an in-scope variable, like print("Hello {foo.bar}")
Neither of these situations seems to be explicitly part of the listed exceptions to the rule, and don't seem like they should be.
Example:
deffibonacci(n):
"""Compute the nth number in the Fibonacci sequence."""ifn==0:
return0elifn==1:
return1else:
returnfibonacci(n-1) +fibonacci(n-2)
classFoo:
BAR=5name="Sarah"day_of_week="Tuesday"print("Hello {name}! It is {day_of_week} today!") # Correctly flagged by RUF027print("Hello {fibonacci}") # Correctly flagged by RUF027print("Hello {fibonacci(1)}") # Should be flagged by RUF027 but is notprint("Hello {Foo.BAR}") # Should be flagged by RUF027 but is not
Yeah, this seems like something that we should catch. It could be that we're deliberately ignoring expressions that are not pure variables although I'll have to check the source code to confirm. Thanks for the report.
We could extend the rule to support more expressions, e.g. attribute access or call expressions. The ideal solution is probably to extract the left-most name and try to lookup that name
With RUF027 enabled, I would expect it to flag both of these, which it currently does not:
print("Hello {foo()}")
print("Hello {foo.bar}")
Neither of these situations seems to be explicitly part of the listed exceptions to the rule, and don't seem like they should be.
Example:
Playground: https://play.ruff.rs/ff81d90f-a1d6-4842-8b1b-b31ede9edbaf
The text was updated successfully, but these errors were encountered: