Replies: 2 comments 6 replies
-
I don't think we have anything like this yet. What would a good rule could look like here? Assert that walrus operators are always parenthesized if they're part of a larger expression? |
Beta Was this translation helpful? Give feedback.
-
Would like to note that there are other "confusing precedence" cases which might be considered along with this one. One I see occasionally is a == b if c else d which is evaluated as (a == b) if c else d while the following is sometimes intended a == (b if c else d) I think it would be good to require clarifying parentheses here. Does the Ruff AST allow checking for parens, or will it require a tokens-level rule? (A tokens rule might get complicated...) |
Beta Was this translation helpful? Give feedback.
-
wrote this condition recently which is actually a bug because
:=
has lowest priority of all operators. i have a few ruff rules as well as mypy enabled, none of them caught it (bool is subclass of int so mypy thought it's fine comparing it to ints later).a quick search for
walrus
gives no results on ruff rules page. is there some rule to guard against this?Beta Was this translation helpful? Give feedback.
All reactions