Skip to content

F811 false positive in match statement #4076

@cgahr

Description

@cgahr

Hi,

really love ruff, such a great tool! It also inspired me to learn Rust ;)

I found the following bug, which can be reproduced with this MWE:

def no_redef(value):
    if value:

        def fun(x, y):
            return x

    else:

        def fun(x, y):
            return y

    return fun


def redef(value):
    match value:
        case True:

            def fun(x, y):
                return x

        case False:

            def fun(x, y):
                return y

    return fun

Running ruff throws the following error which (IMO) is a bug:

> ruff redef.py --isolated
redef.py:24:17: F811 Redefinition of unused `fun` from line 19
Found 1 error.

Why is this a bug?
In my understanding both the no_redef and redef function have the same behavior. Thus, F811 should behave the same for both functions, which is not the case.

This behavior is consistent with flake8/pyflakes, however, I think this is a bug in their code as well and I opened a ticket there too (PyCQA/pyflakes#771).

Ruff version

> ruff --version
ruff 0.0.261

pyproject.toml

[tool.ruff]
select = ["F"]
target-version = "py38"

Constantin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions