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
I'd like to have a linter that checks that all variants are covered by match expression. An example:
from enum import Enum
class Foo(Enum):
A = 1
B = 2
def foo(f: Foo):
var: int
match f:
case Foo.A:
var = 1
print(var)
foo(Foo.B)
ruff check ./ reports that All checks are passed. However, if you run the code it raises UnboundLocalError.
The way to solve it is simple (I guess): check that all branches are covered.
Definitely there can be more complex expression, like case Foo.A | Foo.B, case _ which would be great to cover as well.
The text was updated successfully, but these errors were encountered:
That makes sense. I don't think Ruff is capable of running this today. It will require type inference to know what f evaluates to, to know which branches are possible. We're working on adding support for type-inference but it will take us a while.
I'd like to have a linter that checks that all variants are covered by match expression. An example:
ruff check ./
reports thatAll checks are passed
. However, if you run the code it raises UnboundLocalError.The way to solve it is simple (I guess): check that all branches are covered.
Definitely there can be more complex expression, like
case Foo.A | Foo.B
,case _
which would be great to cover as well.The text was updated successfully, but these errors were encountered: