multiple-class-sub-patterns / E1904ΒΆ
Message emitted:
Multiple sub-patterns for attribute %s
Description:
Emitted when there is more than one sub-pattern for a specific attribute in a class pattern.
Problematic code:
class Book:
__match_args__ = ("title", "year")
def __init__(self, title, year):
self.title = title
self.year = year
def func(item: Book):
match item:
case Book("abc", title="abc"): # [multiple-class-sub-patterns]
...
case Book(year=2000, year=2001): # [multiple-class-sub-patterns]
...
Correct code:
class Book:
__match_args__ = ("title", "year")
def __init__(self, title, year):
self.title = title
self.year = year
def func(item: Book):
match item:
case Book(title="abc"):
...
case Book(year=2000):
...
Related links:
Created by the match_statements checker.