68
68
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
69
69
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
70
70
71
- """basic checker for Python code."""
71
+ """Basic checker for Python code."""
72
72
import collections
73
73
import itertools
74
74
import re
@@ -266,7 +266,7 @@ def in_loop(node: nodes.NodeNG) -> bool:
266
266
267
267
268
268
def in_nested_list (nested_list , obj ):
269
- """return true if the object is an element of <nested_list> or of a nested list."""
269
+ """Return true if the object is an element of <nested_list> or of a nested list."""
270
270
for elmt in nested_list :
271
271
if isinstance (elmt , (list , tuple )):
272
272
if in_nested_list (elmt , obj ):
@@ -398,7 +398,7 @@ def report_by_type_stats(
398
398
stats : LinterStats ,
399
399
old_stats : Optional [LinterStats ],
400
400
):
401
- """make a report of.
401
+ """Make a report of.
402
402
403
403
* percentage of different types documented
404
404
* percentage of different types with a bad name
@@ -838,7 +838,7 @@ def _check_else_on_loop(self, node):
838
838
)
839
839
840
840
def _check_in_loop (self , node , node_name ):
841
- """check that a node is inside a for or while loop."""
841
+ """Check that a node is inside a for or while loop."""
842
842
for parent in node .node_ancestors ():
843
843
if isinstance (parent , (nodes .For , nodes .While )):
844
844
if node not in parent .orelse :
@@ -856,7 +856,7 @@ def _check_in_loop(self, node, node_name):
856
856
self .add_message ("not-in-loop" , node = node , args = node_name )
857
857
858
858
def _check_redefinition (self , redeftype , node ):
859
- """check for redefinition of a function / method / class name."""
859
+ """Check for redefinition of a function / method / class name."""
860
860
parent_frame = node .parent .frame ()
861
861
862
862
# Ignore function stubs created for type information
@@ -933,7 +933,7 @@ def _check_redefinition(self, redeftype, node):
933
933
934
934
935
935
class BasicChecker (_BasicChecker ):
936
- """checks for :
936
+ """Checks for :
937
937
938
938
* doc strings
939
939
* number of arguments, local variables, branches, returns and statements in
@@ -1084,7 +1084,7 @@ def __init__(self, linter):
1084
1084
self ._tryfinallys = None
1085
1085
1086
1086
def open (self ):
1087
- """initialize visit variables and statistics."""
1087
+ """Initialize visit variables and statistics."""
1088
1088
py_version = get_global_option (self , "py-version" )
1089
1089
self ._py38_plus = py_version >= (3 , 8 )
1090
1090
self ._tryfinallys = []
@@ -1158,11 +1158,11 @@ def _check_using_constant_test(self, node, test):
1158
1158
self .add_message ("using-constant-test" , node = node )
1159
1159
1160
1160
def visit_module (self , _ : nodes .Module ) -> None :
1161
- """check module name, docstring and required arguments."""
1161
+ """Check module name, docstring and required arguments."""
1162
1162
self .linter .stats .node_count ["module" ] += 1
1163
1163
1164
1164
def visit_classdef (self , _ : nodes .ClassDef ) -> None :
1165
- """check module name, docstring and redefinition increment branch counter."""
1165
+ """Check module name, docstring and redefinition increment branch counter."""
1166
1166
self .linter .stats .node_count ["klass" ] += 1
1167
1167
1168
1168
@utils .check_messages (
@@ -1299,8 +1299,7 @@ def visit_lambda(self, node: nodes.Lambda) -> None:
1299
1299
1300
1300
@utils .check_messages ("dangerous-default-value" )
1301
1301
def visit_functiondef (self , node : nodes .FunctionDef ) -> None :
1302
- """check function name, docstring, arguments, redefinition, variable names, max
1303
- locals."""
1302
+ """Check function name, docstring, args, redefinition, variable names, locals."""
1304
1303
if node .is_method ():
1305
1304
self .linter .stats .node_count ["method" ] += 1
1306
1305
else :
@@ -1362,7 +1361,7 @@ def visit_return(self, node: nodes.Return) -> None:
1362
1361
1363
1362
@utils .check_messages ("unreachable" )
1364
1363
def visit_continue (self , node : nodes .Continue ) -> None :
1365
- """check is the node has a right sibling (if so, that's some unreachable
1364
+ """Check is the node has a right sibling (if so, that's some unreachable
1366
1365
code)"""
1367
1366
self ._check_unreachable (node )
1368
1367
@@ -1409,7 +1408,7 @@ def _check_misplaced_format_function(self, call_node):
1409
1408
"eval-used" , "exec-used" , "bad-reversed-sequence" , "misplaced-format-function"
1410
1409
)
1411
1410
def visit_call (self , node : nodes .Call ) -> None :
1412
- """visit a Call node -> check if this is not a disallowed builtin.
1411
+ """Visit a Call node -> check if this is not a disallowed builtin.
1413
1412
1414
1413
call and check for * or ** use
1415
1414
"""
@@ -1445,7 +1444,7 @@ def visit_assert(self, node: nodes.Assert) -> None:
1445
1444
1446
1445
@utils .check_messages ("duplicate-key" )
1447
1446
def visit_dict (self , node : nodes .Dict ) -> None :
1448
- """check duplicate key in dictionary."""
1447
+ """Check duplicate key in dictionary."""
1449
1448
keys = set ()
1450
1449
for k , _ in node .items :
1451
1450
if isinstance (k , nodes .Const ):
@@ -1459,15 +1458,15 @@ def visit_dict(self, node: nodes.Dict) -> None:
1459
1458
keys .add (key )
1460
1459
1461
1460
def visit_tryfinally (self , node : nodes .TryFinally ) -> None :
1462
- """update try...finally flag."""
1461
+ """Update ' try...finally' flag."""
1463
1462
self ._tryfinallys .append (node )
1464
1463
1465
1464
def leave_tryfinally (self , _ : nodes .TryFinally ) -> None :
1466
- """update try...finally flag."""
1465
+ """Update ' try...finally' flag."""
1467
1466
self ._tryfinallys .pop ()
1468
1467
1469
1468
def _check_unreachable (self , node ):
1470
- """check unreachable code."""
1469
+ """Check unreachable code."""
1471
1470
unreach_stmt = node .next_sibling ()
1472
1471
if unreach_stmt is not None :
1473
1472
if (
@@ -1483,7 +1482,7 @@ def _check_unreachable(self, node):
1483
1482
self .add_message ("unreachable" , node = unreach_stmt )
1484
1483
1485
1484
def _check_not_in_finally (self , node , node_name , breaker_classes = ()):
1486
- """check that a node is not inside a 'finally' clause of a 'try...finally'
1485
+ """Check that a node is not inside a 'finally' clause of a 'try...finally'
1487
1486
statement.
1488
1487
1489
1488
If we find a parent which type is in breaker_classes before a 'try...finally'
@@ -1503,7 +1502,7 @@ def _check_not_in_finally(self, node, node_name, breaker_classes=()):
1503
1502
_parent = _node .parent
1504
1503
1505
1504
def _check_reversed (self , node ):
1506
- """check that the argument to `reversed` is a sequence."""
1505
+ """Check that the argument to `reversed` is a sequence."""
1507
1506
try :
1508
1507
argument = utils .safe_infer (utils .get_argument_from_call (node , position = 0 ))
1509
1508
except utils .NoSuchArgumentError :
@@ -1960,7 +1959,7 @@ def visit_global(self, node: nodes.Global) -> None:
1960
1959
"disallowed-name" , "invalid-name" , "assign-to-new-keyword" , "non-ascii-name"
1961
1960
)
1962
1961
def visit_assignname (self , node : nodes .AssignName ) -> None :
1963
- """check module level assigned names."""
1962
+ """Check module level assigned names."""
1964
1963
self ._check_assign_to_new_keyword_violation (node .name , node )
1965
1964
frame = node .frame ()
1966
1965
assign_type = node .assign_type ()
@@ -2047,7 +2046,7 @@ def _name_disallowed_by_regex(self, name: str) -> bool:
2047
2046
)
2048
2047
2049
2048
def _check_name (self , node_type , name , node , confidence = interfaces .HIGH ):
2050
- """check for a name using the type's regexp."""
2049
+ """Check for a name using the type's regexp."""
2051
2050
non_ascii_match = self ._non_ascii_rgx_compiled .match (name )
2052
2051
if non_ascii_match is not None :
2053
2052
self ._raise_name_warning (
@@ -2266,7 +2265,7 @@ def _check_docstring(
2266
2265
2267
2266
2268
2267
class PassChecker (_BasicChecker ):
2269
- """check if the pass statement is really necessary."""
2268
+ """Check if the pass statement is really necessary."""
2270
2269
2271
2270
msgs = {
2272
2271
"W0107" : (
@@ -2457,8 +2456,7 @@ def _is_nan(node) -> bool:
2457
2456
)
2458
2457
2459
2458
def _check_literal_comparison (self , literal , node : nodes .Compare ):
2460
- """Check if we compare to a literal, which is usually what we do not want to
2461
- do."""
2459
+ """Check if we compare to a literal, which is not what we usually want to do."""
2462
2460
is_other_literal = isinstance (literal , (nodes .List , nodes .Dict , nodes .Set ))
2463
2461
is_const = False
2464
2462
if isinstance (literal , nodes .Const ):
0 commit comments