@@ -826,14 +826,13 @@ def _check_superfluous_else_continue(self, node: nodes.If) -> None:
826826
827827 @staticmethod
828828 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]
837836 return False
838837
839838 def _is_dict_get_block (self , node : nodes .If ) -> bool :
@@ -1568,12 +1567,10 @@ def visit_boolop(self, node: nodes.BoolOp) -> None:
15681567
15691568 @staticmethod
15701569 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
15771574
15781575 def _check_swap_variables (self , node : nodes .Return | nodes .Assign ) -> None :
15791576 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:
19011898
19021899 All of: condition, true_value and false_value should not be a complex boolean expression
19031900 """
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
19141907
19151908 @staticmethod
19161909 def _and_or_ternary_arguments (
@@ -2093,10 +2086,10 @@ def _is_function_def_never_returning(
20932086 except AttributeError :
20942087 return False # the BoundMethod proxy may be a lambda without a returns
20952088
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
21002093
21012094 def _check_return_at_the_end (self , node : nodes .FunctionDef ) -> None :
21022095 """Check for presence of a *single* return statement at the end of a
0 commit comments