Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter: uncovered branches #11778

Open
antonio-antuan opened this issue Jun 6, 2024 · 1 comment
Open

linter: uncovered branches #11778

antonio-antuan opened this issue Jun 6, 2024 · 1 comment
Labels
rule Implementing or modifying a lint rule type-inference Requires more advanced type inference.

Comments

@antonio-antuan
Copy link

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.

@MichaReiser MichaReiser added the type-inference Requires more advanced type inference. label Jun 7, 2024
@MichaReiser
Copy link
Member

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.

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule type-inference Requires more advanced type inference.
Projects
None yet
Development

No branches or pull requests

2 participants