101
101
102
102
103
103
class NamingStyle :
104
- """It may seem counterintuitive that single naming style has multiple "accepted"
105
- forms of regular expressions, but we need to special-case stuff like dunder names
106
- in method names.
104
+ """It may seem counterintuitive that single naming style has multiple
105
+ "accepted" forms of regular expressions, but we need to special-case stuff
106
+ like dunder names in method names.
107
107
"""
108
108
109
109
ANY : Pattern [str ] = re .compile (".*" )
@@ -231,8 +231,9 @@ class AnyStyle(NamingStyle):
231
231
232
232
233
233
def _redefines_import (node ):
234
- """Detect that the given node (AssignName) is inside an
235
- exception handler and redefines an import from the tryexcept body.
234
+ """Detect that the given node (AssignName) is inside an exception handler
235
+ and redefines an import from the tryexcept body.
236
+
236
237
Returns True if the node redefines an import, False otherwise.
237
238
"""
238
239
current = node
@@ -267,7 +268,7 @@ def in_loop(node: nodes.NodeNG) -> bool:
267
268
268
269
def in_nested_list (nested_list , obj ):
269
270
"""Return true if the object is an element of <nested_list> or of a nested
270
- list
271
+ list.
271
272
"""
272
273
for elmt in nested_list :
273
274
if isinstance (elmt , (list , tuple )):
@@ -337,8 +338,8 @@ def _is_multi_naming_match(match, node_type, confidence):
337
338
def _get_properties (config ):
338
339
"""Returns a tuple of property classes and names.
339
340
340
- Property classes are fully qualified, such as 'abc.abstractproperty' and
341
- property names are the actual names, such as 'abstract_property'.
341
+ Property classes are fully qualified, i.e. 'abc.abstractproperty'
342
+ and property names are the actual names, i.e. 'abstract_property'.
342
343
"""
343
344
property_classes = {BUILTIN_PROPERTY }
344
345
property_names = set () # Not returning 'property', it has its own check.
@@ -390,8 +391,8 @@ def _determine_function_name_type(node: nodes.FunctionDef, config=None):
390
391
def _has_abstract_methods (node ):
391
392
"""Determine if the given `node` has abstract methods.
392
393
393
- The methods should be made abstract by decorating them
394
- with `abc` decorators.
394
+ The methods should be made abstract by decorating them with `abc`
395
+ decorators.
395
396
"""
396
397
return len (utils .unimplemented_abstract_methods (node )) > 0
397
398
@@ -784,9 +785,7 @@ def visit_nonlocal(self, node: nodes.Nonlocal) -> None:
784
785
785
786
@utils .check_messages ("abstract-class-instantiated" )
786
787
def visit_call (self , node : nodes .Call ) -> None :
787
- """Check instantiating abstract class with
788
- abc.ABCMeta as metaclass.
789
- """
788
+ """Check instantiating abstract class with abc.ABCMeta as metaclass."""
790
789
for inferred in infer_all (node .func ):
791
790
self ._check_inferred_class_is_abstract (inferred , node )
792
791
@@ -1167,8 +1166,8 @@ def visit_module(self, _: nodes.Module) -> None:
1167
1166
self .linter .stats .node_count ["module" ] += 1
1168
1167
1169
1168
def visit_classdef (self , _ : nodes .ClassDef ) -> None :
1170
- """Check module name, docstring and redefinition
1171
- increment branch counter
1169
+ """Check module name, docstring and redefinition increment branch
1170
+ counter.
1172
1171
"""
1173
1172
self .linter .stats .node_count ["klass" ] += 1
1174
1173
@@ -1306,8 +1305,8 @@ def visit_lambda(self, node: nodes.Lambda) -> None:
1306
1305
1307
1306
@utils .check_messages ("dangerous-default-value" )
1308
1307
def visit_functiondef (self , node : nodes .FunctionDef ) -> None :
1309
- """Check function name, docstring, arguments, redefinition,
1310
- variable names, max locals
1308
+ """Check function name, docstring, arguments, redefinition, variable
1309
+ names, max locals.
1311
1310
"""
1312
1311
if node .is_method ():
1313
1312
self .linter .stats .node_count ["method" ] += 1
@@ -1370,8 +1369,8 @@ def visit_return(self, node: nodes.Return) -> None:
1370
1369
1371
1370
@utils .check_messages ("unreachable" )
1372
1371
def visit_continue (self , node : nodes .Continue ) -> None :
1373
- """Check is the node has a right sibling (if so, that's some unreachable
1374
- code)
1372
+ """Check is the node has a right sibling (if so, that's some
1373
+ unreachable code)
1375
1374
"""
1376
1375
self ._check_unreachable (node )
1377
1376
@@ -1389,8 +1388,8 @@ def visit_break(self, node: nodes.Break) -> None:
1389
1388
1390
1389
@utils .check_messages ("unreachable" )
1391
1390
def visit_raise (self , node : nodes .Raise ) -> None :
1392
- """Check if the node has a right sibling (if so, that's some unreachable
1393
- code)
1391
+ """Check if the node has a right sibling (if so, that's some
1392
+ unreachable code)
1394
1393
"""
1395
1394
self ._check_unreachable (node )
1396
1395
@@ -1419,7 +1418,8 @@ def _check_misplaced_format_function(self, call_node):
1419
1418
"eval-used" , "exec-used" , "bad-reversed-sequence" , "misplaced-format-function"
1420
1419
)
1421
1420
def visit_call (self , node : nodes .Call ) -> None :
1422
- """Visit a Call node -> check if this is not a disallowed builtin
1421
+ """Visit a Call node -> check if this is not a disallowed builtin.
1422
+
1423
1423
call and check for * or ** use
1424
1424
"""
1425
1425
self ._check_misplaced_format_function (node )
@@ -1494,8 +1494,9 @@ def _check_unreachable(self, node):
1494
1494
def _check_not_in_finally (self , node , node_name , breaker_classes = ()):
1495
1495
"""Check that a node is not inside a 'finally' clause of a
1496
1496
'try...finally' statement.
1497
- If we find a parent which type is in breaker_classes before
1498
- a 'try...finally' block we skip the whole check.
1497
+
1498
+ If we find a parent which type is in breaker_classes before a
1499
+ 'try...finally' block we skip the whole check.
1499
1500
"""
1500
1501
# if self._tryfinallys is empty, we're not an in try...finally block
1501
1502
if not self ._tryfinallys :
@@ -2263,8 +2264,8 @@ def visit_pass(self, node: nodes.Pass) -> None:
2263
2264
2264
2265
2265
2266
def _is_one_arg_pos_call (call ):
2266
- """Is this a call with exactly 1 argument,
2267
- where that argument is positional?
2267
+ """Is this a call with exactly 1 argument, where that argument is
2268
+ positional?
2268
2269
"""
2269
2270
return isinstance (call , nodes .Call ) and len (call .args ) == 1 and not call .keywords
2270
2271
@@ -2436,7 +2437,9 @@ def _is_nan(node) -> bool:
2436
2437
)
2437
2438
2438
2439
def _check_literal_comparison (self , literal , node : nodes .Compare ):
2439
- """Check if we compare to a literal, which is usually what we do not want to do."""
2440
+ """Check if we compare to a literal, which is usually what we do not
2441
+ want to do.
2442
+ """
2440
2443
is_other_literal = isinstance (literal , (nodes .List , nodes .Dict , nodes .Set ))
2441
2444
is_const = False
2442
2445
if isinstance (literal , nodes .Const ):
@@ -2450,6 +2453,7 @@ def _check_literal_comparison(self, literal, node: nodes.Compare):
2450
2453
2451
2454
def _check_logical_tautology (self , node : nodes .Compare ):
2452
2455
"""Check if identifier is compared against itself.
2456
+
2453
2457
:param node: Compare node
2454
2458
:Example:
2455
2459
val = 786
0 commit comments