@@ -167,15 +167,15 @@ def _is_trivial_super_delegation(function: nodes.FunctionDef) -> bool:
167
167
return False
168
168
169
169
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
176
176
177
177
# Anything other than a super call is non-trivial.
178
- super_call = safe_infer (call . func . expr )
178
+ super_call = safe_infer (expr )
179
179
if not isinstance (super_call , astroid .objects .Super ):
180
180
return False
181
181
@@ -1844,33 +1844,27 @@ def _check_classmethod_declaration(self, node: nodes.Assign) -> None:
1844
1844
is defined.
1845
1845
`node` is an assign node.
1846
1846
"""
1847
- if not isinstance (node .value , nodes .Call ):
1848
- return
1849
-
1850
1847
# 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
1857
1857
1858
1858
msg = (
1859
1859
"no-classmethod-decorator"
1860
- if func . name == "classmethod"
1860
+ if name == "classmethod"
1861
1861
else "no-staticmethod-decorator"
1862
1862
)
1863
1863
# assignment must be at a class scope
1864
1864
parent_class = node .scope ()
1865
1865
if not isinstance (parent_class , nodes .ClassDef ):
1866
1866
return
1867
1867
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
1874
1868
if any (method_name == member .name for member in parent_class .mymethods ()):
1875
1869
self .add_message (msg , node = node .targets [0 ])
1876
1870
@@ -2383,16 +2377,16 @@ def _is_mandatory_method_param(self, node: nodes.NodeNG) -> bool:
2383
2377
first_attr = self ._first_attrs [- 1 ]
2384
2378
else :
2385
2379
# 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 (
2387
2381
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
2396
2390
return isinstance (node , nodes .Name ) and node .name == first_attr
2397
2391
2398
2392
0 commit comments