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

F821: Undefined name in match capture patterns #3096

Closed
mikeroll opened this issue Feb 21, 2023 · 4 comments · Fixed by #3098
Closed

F821: Undefined name in match capture patterns #3096

mikeroll opened this issue Feb 21, 2023 · 4 comments · Fixed by #3098
Assignees
Labels
bug Something isn't working

Comments

@mikeroll
Copy link

First of all, big thanks and congrats on shipping match support! Looks like it's not quite perfect yet as I catch a false-positive F821 with a very simple snippet:

def test(provided: int) -> int:
    match provided:
        case captured:
            return captured  # F821 Undefined name `captured`
❯ ruff --version
ruff 0.0.250
@charliermarsh charliermarsh added the bug Something isn't working label Feb 21, 2023
@charliermarsh charliermarsh self-assigned this Feb 21, 2023
@charliermarsh
Copy link
Member

Thank you!

@charliermarsh
Copy link
Member

Will fix this. Please keep filing issues you run into with match. My focus was primarily on getting the syntax working (and traversals working within the linter), so the rules probably have rough edges.

@dpassen
Copy link

dpassen commented Feb 21, 2023

Not sure if this is the same issue or just very similar:

from dataclasses import dataclass


@dataclass
class Car:
    make: str
    model: str


match Car("Toyota", "Corolla"):
    case Car("Toyota", model):
        print(f"Nice {model}. I love what you do for me, Toyota!")

also yields an F821 Undefined name 'model'

@charliermarsh
Copy link
Member

Same issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants