@@ -558,9 +558,10 @@ def _dummy_rgx(self) -> Pattern[str]:
558
558
559
559
@staticmethod
560
560
def _is_bool_const (node : nodes .Return | nodes .Assign ) -> bool :
561
- return isinstance (node .value , nodes .Const ) and isinstance (
562
- node .value .value , bool
563
- )
561
+ match node .value :
562
+ case nodes .Const (value = bool ()):
563
+ return True
564
+ return False
564
565
565
566
def _is_actual_elif (self , node : nodes .If | nodes .Try ) -> bool :
566
567
"""Check if the given node is an actual elif.
@@ -826,14 +827,13 @@ def _check_superfluous_else_continue(self, node: nodes.If) -> None:
826
827
827
828
@staticmethod
828
829
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]
830
+ match (node_a , node_b ):
831
+ case (
832
+ [nodes .Name (name = a ), nodes .Name (name = b )]
833
+ | [nodes .AssignName (name = a ), nodes .AssignName (name = b )]
834
+ | [nodes .Const (value = a ), nodes .Const (value = b )]
835
+ ):
836
+ return a == b # type: ignore[no-any-return]
837
837
return False
838
838
839
839
def _is_dict_get_block (self , node : nodes .If ) -> bool :
@@ -1568,12 +1568,10 @@ def visit_boolop(self, node: nodes.BoolOp) -> None:
1568
1568
1569
1569
@staticmethod
1570
1570
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
- )
1571
+ match node :
1572
+ case nodes .Assign (targets = [nodes .AssignName ()], value = nodes .Name ()):
1573
+ return True
1574
+ return False
1577
1575
1578
1576
def _check_swap_variables (self , node : nodes .Return | nodes .Assign ) -> None :
1579
1577
if not node .next_sibling () or not node .next_sibling ().next_sibling ():
@@ -1901,16 +1899,12 @@ def _is_and_or_ternary(node: nodes.NodeNG | None) -> bool:
1901
1899
1902
1900
All of: condition, true_value and false_value should not be a complex boolean expression
1903
1901
"""
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
- )
1902
+ match node :
1903
+ case nodes .BoolOp (
1904
+ op = "or" , values = [nodes .BoolOp (op = "and" , values = [_, v1 ]), v2 ]
1905
+ ) if not (isinstance (v2 , nodes .BoolOp ) or isinstance (v1 , nodes .BoolOp )):
1906
+ return True
1907
+ return False
1914
1908
1915
1909
@staticmethod
1916
1910
def _and_or_ternary_arguments (
@@ -2093,10 +2087,12 @@ def _is_function_def_never_returning(
2093
2087
except AttributeError :
2094
2088
return False # the BoundMethod proxy may be a lambda without a returns
2095
2089
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" })
2090
+ match returns :
2091
+ case nodes .Attribute (attrname = "NoReturn" | "Never" ) | nodes .Name (
2092
+ name = "NoReturn" | "Never"
2093
+ ):
2094
+ return True
2095
+ return False
2100
2096
2101
2097
def _check_return_at_the_end (self , node : nodes .FunctionDef ) -> None :
2102
2098
"""Check for presence of a *single* return statement at the end of a
0 commit comments