pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive with match/case (but not with if/elif/else)

Open clo-vis opened this issue 3 years ago • 0 comments

Bug description

def function_a() -> None:
    print("a")


def function_b() -> None:
    print("a")


def test1(function_to_choose: str) -> None:
    match function_to_choose:
        case "a":
            function = function_a  # line 12
        case "b":
            function = function_b
        case "c":
            def function() -> None:   # false positive: function already defined line 12 (function-redefined)
                print("case c")

        case _:
            raise AssertionError(function_to_choose)

    function()


def test2(function_to_choose: str) -> None:
    if function_to_choose == "a":
        function = function_a
    elif function_to_choose == "b":
        function = function_b
    elif function_to_choose == "c":

        def function() -> None:
            print("case c")

    else:
        raise AssertionError(function_to_choose)

    function()


Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:16:12: E0102: function already defined line 12 (function-redefined)

Expected behavior

No errors.

Pylint version

pylint 2.15.2
astroid 2.12.9
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]

OS / Environment

Microsoft Windows [Version 10.0.19042.1889]

Additional dependencies

No response

clo-vis avatar Sep 15 '22 20:09 clo-vis