Skip to content

N806, N815, and N816 ignore case patterns #16502

@dscorbett

Description

@dscorbett

Summary

non-lowercase-variable-in-function (N806), mixed-case-variable-in-class-scope (N815), and mixed-case-variable-in-global-scope (N816) have false negatives for variables assigned in case patterns. Each of the following examples includes tP as a true positive to show that the rule is running plus one or two false negatives.

N806:

$ cat >n806.py <<'# EOF'
def f():
    tP = 0
    match tP:
        case fN: ...
# EOF

$ ruff --isolated check --output-format concise --select N806 n806.py
n806.py:2:5: N806 Variable `tP` in function should be lowercase
Found 1 error.

N815:

$ cat >n815.py <<'# EOF'
class C:
    tP = 0
    match tP:
        case int(fN): ...
# EOF

$ ruff --isolated check --output-format concise --select N815 n815.py
n815.py:2:5: N815 Variable `tP` in class scope should not be mixedCase
Found 1 error.

N816:

$ cat >n816.py <<'# EOF'
tP = 0
match tP:
    case fN1 as fN2: ...
# EOF

$ ruff --isolated check --output-format concise --select N816 n816.py
n816.py:1:1: N816 Variable `tP` in global scope should not be mixedCase
Found 1 error.

Version

ruff 0.9.9 (091d0af 2025-02-28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions