Skip to content

Advanced pattern matching support #887

Description

@sharkdp

We already have basic support for control flow analysis and type narrowing in match statements, but our support is not complete. The list below shows some examples of things that are not working yet, but is probably not exhaustive:

  • Type inference for names that are bound in patterns:

    from dataclasses import dataclass
    
    @dataclass
    class Person:
        name: str
        age: int
    
    def f(person: Person):
        match person:
            case Person(name, age):
                reveal_type(name)  # @Todo(`match` pattern definition types)
                reveal_type(age)  # @Todo(`match` pattern definition types)
    
    def g(xs: list[int]):
        match xs:
            case [1, 2, x]:
                reveal_type(x)  # @Todo(`match` pattern definition types)
  • Support for __match_args__

  • Matching on builtin classes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions