@@ -167,15 +167,15 @@ def _is_trivial_super_delegation(function: nodes.FunctionDef) -> bool:
167167 return False
168168
169169 call = statement .value
170- if (
171- not isinstance ( call , nodes .Call )
172- # Not a super() attribute access.
173- or not isinstance ( call . func , nodes . Attribute )
174- ):
175- return False
170+ match call := statement . value :
171+ case nodes .Call ( func = nodes . Attribute ( expr = expr )):
172+ pass
173+ case _:
174+ # Not a super() attribute access.
175+ return False
176176
177177 # Anything other than a super call is non-trivial.
178- super_call = safe_infer (call . func . expr )
178+ super_call = safe_infer (expr )
179179 if not isinstance (super_call , astroid .objects .Super ):
180180 return False
181181
@@ -1844,33 +1844,27 @@ def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
18441844 is defined.
18451845 `node` is an assign node.
18461846 """
1847- if not isinstance (node .value , nodes .Call ):
1848- return
1849-
18501847 # check the function called is "classmethod" or "staticmethod"
1851- func = node .value .func
1852- if not isinstance (func , nodes .Name ) or func .name not in (
1853- "classmethod" ,
1854- "staticmethod" ,
1855- ):
1856- return
1848+ # Check if the arg passed to classmethod is a class member
1849+ match node .value :
1850+ case nodes .Call (
1851+ func = nodes .Name (name = "classmethod" | "staticmethod" as name ),
1852+ args = [nodes .Name (name = method_name ), * _],
1853+ ):
1854+ pass
1855+ case _:
1856+ return
18571857
18581858 msg = (
18591859 "no-classmethod-decorator"
1860- if func . name == "classmethod"
1860+ if name == "classmethod"
18611861 else "no-staticmethod-decorator"
18621862 )
18631863 # assignment must be at a class scope
18641864 parent_class = node .scope ()
18651865 if not isinstance (parent_class , nodes .ClassDef ):
18661866 return
18671867
1868- # Check if the arg passed to classmethod is a class member
1869- classmeth_arg = node .value .args [0 ]
1870- if not isinstance (classmeth_arg , nodes .Name ):
1871- return
1872-
1873- method_name = classmeth_arg .name
18741868 if any (method_name == member .name for member in parent_class .mymethods ()):
18751869 self .add_message (msg , node = node .targets [0 ])
18761870
@@ -2383,16 +2377,16 @@ def _is_mandatory_method_param(self, node: nodes.NodeNG) -> bool:
23832377 first_attr = self ._first_attrs [- 1 ]
23842378 else :
23852379 # It's possible the function was already unregistered.
2386- closest_func = utils .get_node_first_ancestor_of_type (
2380+ match closest_func : = utils .get_node_first_ancestor_of_type (
23872381 node , nodes .FunctionDef
2388- )
2389- if closest_func is None :
2390- return False
2391- if not closest_func .is_bound ():
2392- return False
2393- if not closest_func . args . args :
2394- return False
2395- first_attr = closest_func . args . args [ 0 ]. name
2382+ ):
2383+ case nodes . FunctionDef (
2384+ args = nodes . Arguments ( args = [ nodes . AssignName ( name = first_attr ), * _])
2385+ ) if closest_func .is_bound ():
2386+ pass
2387+ case _ :
2388+ return False
2389+ # pylint: disable=possibly-used-before-assignment
23962390 return isinstance (node , nodes .Name ) and node .name == first_attr
23972391
23982392
0 commit comments