@@ -826,14 +826,13 @@ def _check_superfluous_else_continue(self, node: nodes.If) -> None:
826
826
827
827
@staticmethod
828
828
def _type_and_name_are_equal (node_a : Any , node_b : Any ) -> bool :
829
- if isinstance (node_a , nodes .Name ) and isinstance (node_b , nodes .Name ):
830
- return node_a .name == node_b .name # type: ignore[no-any-return]
831
- if isinstance (node_a , nodes .AssignName ) and isinstance (
832
- node_b , nodes .AssignName
833
- ):
834
- return node_a .name == node_b .name # type: ignore[no-any-return]
835
- if isinstance (node_a , nodes .Const ) and isinstance (node_b , nodes .Const ):
836
- return node_a .value == node_b .value # type: ignore[no-any-return]
829
+ match (node_a , node_b ):
830
+ case (
831
+ [nodes .Name (name = a ), nodes .Name (name = b )]
832
+ | [nodes .AssignName (name = a ), nodes .AssignName (name = b )]
833
+ | [nodes .Const (value = a ), nodes .Const (value = b )]
834
+ ):
835
+ return a == b # type: ignore[no-any-return]
837
836
return False
838
837
839
838
def _is_dict_get_block (self , node : nodes .If ) -> bool :
@@ -1568,12 +1567,10 @@ def visit_boolop(self, node: nodes.BoolOp) -> None:
1568
1567
1569
1568
@staticmethod
1570
1569
def _is_simple_assignment (node : nodes .NodeNG | None ) -> bool :
1571
- return (
1572
- isinstance (node , nodes .Assign )
1573
- and len (node .targets ) == 1
1574
- and isinstance (node .targets [0 ], nodes .AssignName )
1575
- and isinstance (node .value , nodes .Name )
1576
- )
1570
+ match node :
1571
+ case nodes .Assign (targets = [nodes .AssignName ()], value = nodes .Name ()):
1572
+ return True
1573
+ return False
1577
1574
1578
1575
def _check_swap_variables (self , node : nodes .Return | nodes .Assign ) -> None :
1579
1576
if not node .next_sibling () or not node .next_sibling ().next_sibling ():
@@ -1901,16 +1898,12 @@ def _is_and_or_ternary(node: nodes.NodeNG | None) -> bool:
1901
1898
1902
1899
All of: condition, true_value and false_value should not be a complex boolean expression
1903
1900
"""
1904
- return (
1905
- isinstance (node , nodes .BoolOp )
1906
- and node .op == "or"
1907
- and len (node .values ) == 2
1908
- and isinstance (node .values [0 ], nodes .BoolOp )
1909
- and not isinstance (node .values [1 ], nodes .BoolOp )
1910
- and node .values [0 ].op == "and"
1911
- and not isinstance (node .values [0 ].values [1 ], nodes .BoolOp )
1912
- and len (node .values [0 ].values ) == 2
1913
- )
1901
+ match node :
1902
+ case nodes .BoolOp (
1903
+ op = "or" , values = [nodes .BoolOp (op = "and" , values = [_, v1 ]), v2 ]
1904
+ ) if not (isinstance (v2 , nodes .BoolOp ) or isinstance (v1 , nodes .BoolOp )):
1905
+ return True
1906
+ return False
1914
1907
1915
1908
@staticmethod
1916
1909
def _and_or_ternary_arguments (
@@ -2093,10 +2086,10 @@ def _is_function_def_never_returning(
2093
2086
except AttributeError :
2094
2087
return False # the BoundMethod proxy may be a lambda without a returns
2095
2088
2096
- return (
2097
- isinstance ( returns , nodes .Attribute )
2098
- and returns . attrname in {"NoReturn" , "Never" }
2099
- ) or ( isinstance ( returns , nodes . Name ) and returns . name in { "NoReturn" , "Never" })
2089
+ match returns :
2090
+ case nodes .Attribute ( attrname = name ) | nodes . Name ( name = name ):
2091
+ return name in {"NoReturn" , "Never" }
2092
+ return False
2100
2093
2101
2094
def _check_return_at_the_end (self , node : nodes .FunctionDef ) -> None :
2102
2095
"""Check for presence of a *single* return statement at the end of a
0 commit comments