Skip to content

False-positive: bare-name-capture-pattern is thrown even when there is a guard that would prevent a syntax exception #10666

@calamitous-crab

Description

@calamitous-crab

Bug description

a = 'a'
b = 'b'
s = 'a'

match s:
    case a if a in "crab":
        pass
    case b if b in "song":
        pass

Configuration

Command used

pylint hi.py -E

Pylint output

************* Module hi
hi.py:6:9: E1901: The name capture `case a` makes the remaining patterns unreachable. Use a dotted name (for example an enum) to fix this. (bare-name-capture-pattern)

Expected behavior

I would expect there to be no error from pylint since there is no syntax error thrown by the python interpreter with the same code.

>>> a = 'a'
>>> b = 'b'
>>> s = 'a'
>>> match s:
...     case a if a in "crab":
...         pass
...     case b if b in "song":
...         pass
...
>>>

Pylint version

pylint 4.0.0
astroid 4.0.1
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]

OS / Environment

Windows 11
Command Prompt
Python version 3.10.11

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate 🐫Duplicate of an already existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions