Skip to content

Commit a675d16

Browse files
Apply suggestions from code review
1 parent 75ceea8 commit a675d16

21 files changed

+113
-130
lines changed

examples/custom_raw.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class MyRawChecker(BaseChecker):
13-
"""check for line continuations with '\' instead of using triple quoted string or
13+
"""Check for line continuations with '\' instead of using triple quoted string or
1414
parenthesis."""
1515

1616
__implements__ = IRawChecker
@@ -29,7 +29,7 @@ class MyRawChecker(BaseChecker):
2929
options = ()
3030

3131
def process_module(self, node: nodes.Module) -> None:
32-
"""process a module.
32+
"""Process a module.
3333
3434
the module's content is accessible via node.stream() function
3535
"""

pylint/checkers/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2020
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
2121

22-
"""utilities methods and classes for checkers.
22+
"""Utilities methods and classes for checkers.
2323
2424
Base id of standard checkers (used in msg and report ids):
2525
01: base
@@ -65,7 +65,7 @@ def table_lines_from_stats(
6565
old_stats: Optional[LinterStats],
6666
stat_type: Literal["duplicated_lines", "message_types"],
6767
) -> List[str]:
68-
"""get values listed in <columns> from <stats> and <old_stats>, and return a
68+
"""Get values listed in <columns> from <stats> and <old_stats>, and return a
6969
formatted list of values, designed to be given to a ureport.Table object."""
7070
lines: List[str] = []
7171
if stat_type == "duplicated_lines":
@@ -126,7 +126,7 @@ def table_lines_from_stats(
126126

127127

128128
def initialize(linter):
129-
"""initialize linter with checkers in this package."""
129+
"""Initialize linter with checkers in this package."""
130130
register_plugins(linter, __path__[0])
131131

132132

pylint/checkers/base.py

+22-24
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6969
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
7070

71-
"""basic checker for Python code."""
71+
"""Basic checker for Python code."""
7272
import collections
7373
import itertools
7474
import re
@@ -266,7 +266,7 @@ def in_loop(node: nodes.NodeNG) -> bool:
266266

267267

268268
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."""
270270
for elmt in nested_list:
271271
if isinstance(elmt, (list, tuple)):
272272
if in_nested_list(elmt, obj):
@@ -398,7 +398,7 @@ def report_by_type_stats(
398398
stats: LinterStats,
399399
old_stats: Optional[LinterStats],
400400
):
401-
"""make a report of.
401+
"""Make a report of.
402402
403403
* percentage of different types documented
404404
* percentage of different types with a bad name
@@ -838,7 +838,7 @@ def _check_else_on_loop(self, node):
838838
)
839839

840840
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."""
842842
for parent in node.node_ancestors():
843843
if isinstance(parent, (nodes.For, nodes.While)):
844844
if node not in parent.orelse:
@@ -856,7 +856,7 @@ def _check_in_loop(self, node, node_name):
856856
self.add_message("not-in-loop", node=node, args=node_name)
857857

858858
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."""
860860
parent_frame = node.parent.frame()
861861

862862
# Ignore function stubs created for type information
@@ -933,7 +933,7 @@ def _check_redefinition(self, redeftype, node):
933933

934934

935935
class BasicChecker(_BasicChecker):
936-
"""checks for :
936+
"""Checks for :
937937
938938
* doc strings
939939
* number of arguments, local variables, branches, returns and statements in
@@ -1084,7 +1084,7 @@ def __init__(self, linter):
10841084
self._tryfinallys = None
10851085

10861086
def open(self):
1087-
"""initialize visit variables and statistics."""
1087+
"""Initialize visit variables and statistics."""
10881088
py_version = get_global_option(self, "py-version")
10891089
self._py38_plus = py_version >= (3, 8)
10901090
self._tryfinallys = []
@@ -1158,11 +1158,11 @@ def _check_using_constant_test(self, node, test):
11581158
self.add_message("using-constant-test", node=node)
11591159

11601160
def visit_module(self, _: nodes.Module) -> None:
1161-
"""check module name, docstring and required arguments."""
1161+
"""Check module name, docstring and required arguments."""
11621162
self.linter.stats.node_count["module"] += 1
11631163

11641164
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."""
11661166
self.linter.stats.node_count["klass"] += 1
11671167

11681168
@utils.check_messages(
@@ -1299,8 +1299,7 @@ def visit_lambda(self, node: nodes.Lambda) -> None:
12991299

13001300
@utils.check_messages("dangerous-default-value")
13011301
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."""
13041303
if node.is_method():
13051304
self.linter.stats.node_count["method"] += 1
13061305
else:
@@ -1362,7 +1361,7 @@ def visit_return(self, node: nodes.Return) -> None:
13621361

13631362
@utils.check_messages("unreachable")
13641363
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
13661365
code)"""
13671366
self._check_unreachable(node)
13681367

@@ -1409,7 +1408,7 @@ def _check_misplaced_format_function(self, call_node):
14091408
"eval-used", "exec-used", "bad-reversed-sequence", "misplaced-format-function"
14101409
)
14111410
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.
14131412
14141413
call and check for * or ** use
14151414
"""
@@ -1445,7 +1444,7 @@ def visit_assert(self, node: nodes.Assert) -> None:
14451444

14461445
@utils.check_messages("duplicate-key")
14471446
def visit_dict(self, node: nodes.Dict) -> None:
1448-
"""check duplicate key in dictionary."""
1447+
"""Check duplicate key in dictionary."""
14491448
keys = set()
14501449
for k, _ in node.items:
14511450
if isinstance(k, nodes.Const):
@@ -1459,15 +1458,15 @@ def visit_dict(self, node: nodes.Dict) -> None:
14591458
keys.add(key)
14601459

14611460
def visit_tryfinally(self, node: nodes.TryFinally) -> None:
1462-
"""update try...finally flag."""
1461+
"""Update 'try...finally' flag."""
14631462
self._tryfinallys.append(node)
14641463

14651464
def leave_tryfinally(self, _: nodes.TryFinally) -> None:
1466-
"""update try...finally flag."""
1465+
"""Update 'try...finally' flag."""
14671466
self._tryfinallys.pop()
14681467

14691468
def _check_unreachable(self, node):
1470-
"""check unreachable code."""
1469+
"""Check unreachable code."""
14711470
unreach_stmt = node.next_sibling()
14721471
if unreach_stmt is not None:
14731472
if (
@@ -1483,7 +1482,7 @@ def _check_unreachable(self, node):
14831482
self.add_message("unreachable", node=unreach_stmt)
14841483

14851484
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'
14871486
statement.
14881487
14891488
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=()):
15031502
_parent = _node.parent
15041503

15051504
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."""
15071506
try:
15081507
argument = utils.safe_infer(utils.get_argument_from_call(node, position=0))
15091508
except utils.NoSuchArgumentError:
@@ -1960,7 +1959,7 @@ def visit_global(self, node: nodes.Global) -> None:
19601959
"disallowed-name", "invalid-name", "assign-to-new-keyword", "non-ascii-name"
19611960
)
19621961
def visit_assignname(self, node: nodes.AssignName) -> None:
1963-
"""check module level assigned names."""
1962+
"""Check module level assigned names."""
19641963
self._check_assign_to_new_keyword_violation(node.name, node)
19651964
frame = node.frame()
19661965
assign_type = node.assign_type()
@@ -2047,7 +2046,7 @@ def _name_disallowed_by_regex(self, name: str) -> bool:
20472046
)
20482047

20492048
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."""
20512050
non_ascii_match = self._non_ascii_rgx_compiled.match(name)
20522051
if non_ascii_match is not None:
20532052
self._raise_name_warning(
@@ -2266,7 +2265,7 @@ def _check_docstring(
22662265

22672266

22682267
class PassChecker(_BasicChecker):
2269-
"""check if the pass statement is really necessary."""
2268+
"""Check if the pass statement is really necessary."""
22702269

22712270
msgs = {
22722271
"W0107": (
@@ -2457,8 +2456,7 @@ def _is_nan(node) -> bool:
24572456
)
24582457

24592458
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."""
24622460
is_other_literal = isinstance(literal, (nodes.List, nodes.Dict, nodes.Set))
24632461
is_const = False
24642462
if isinstance(literal, nodes.Const):

pylint/checkers/base_checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BaseChecker(OptionsProviderMixIn):
4848
enabled: bool = True
4949

5050
def __init__(self, linter=None):
51-
"""checker instances should have the linter as argument.
51+
"""Checker instances should have the linter as argument.
5252
5353
:param ILinter linter: is an object implementing ILinter.
5454
"""

pylint/checkers/classes/class_checker.py

+15-24
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ def _has_data_descriptor(cls, attr):
352352

353353

354354
def _called_in_methods(func, klass, methods):
355-
"""Check if the func was called in any of the given methods, belonging to the.
356-
357-
*klass*.
355+
"""Check if the function was called in any of the methods belonging to 'klass'.
358356
359357
Returns True if so, False otherwise.
360358
"""
@@ -684,7 +682,7 @@ def accessed(self, scope):
684682

685683

686684
class ClassChecker(BaseChecker):
687-
"""checks for :
685+
"""Checks for :
688686
689687
* methods without self as first argument
690688
* overridden methods signature
@@ -794,7 +792,7 @@ def _ignore_mixin(self):
794792
"duplicate-bases",
795793
)
796794
def visit_classdef(self, node: nodes.ClassDef) -> None:
797-
"""init visit variable _accessed."""
795+
"""Init visit variable _accessed."""
798796
self._check_bases_classes(node)
799797
# if not an exception or a metaclass
800798
if node.type == "class" and has_known_bases(node):
@@ -1069,7 +1067,7 @@ def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
10691067
)
10701068

10711069
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
1072-
"""check method arguments, overriding."""
1070+
"""Check method arguments, overriding."""
10731071
# ignore actual functions
10741072
if not node.is_method():
10751073
return
@@ -1385,9 +1383,9 @@ def _check_slots_elt(self, elt, node):
13851383
)
13861384

13871385
def leave_functiondef(self, node: nodes.FunctionDef) -> None:
1388-
"""on method node, check if this method couldn't be a function.
1386+
"""On method node, check if this method couldn't be a function.
13891387
1390-
ignore class, static and abstract methods, initializer, methods overridden from
1388+
Ignore class, static and abstract methods, initializer, methods overridden from
13911389
a parent class.
13921390
"""
13931391
if node.is_method():
@@ -1414,7 +1412,7 @@ def leave_functiondef(self, node: nodes.FunctionDef) -> None:
14141412
leave_asyncfunctiondef = leave_functiondef
14151413

14161414
def visit_attribute(self, node: nodes.Attribute) -> None:
1417-
"""check if the getattr is an access to a class member if so, register it.
1415+
"""Check if the 'getattr' is an access to a class member if so, register it.
14181416
14191417
Also check for access to protected class member from outside its class (but
14201418
ignore __special__ methods)
@@ -1676,10 +1674,7 @@ def _is_classmethod(func):
16761674

16771675
@staticmethod
16781676
def _is_inferred_instance(expr, klass):
1679-
"""Check if the inferred value of the given *expr* is an instance of.
1680-
1681-
*klass*.
1682-
"""
1677+
"""Check if the inferred value of 'expr' is an instance of 'klass'."""
16831678

16841679
inferred = safe_infer(expr)
16851680
if not isinstance(inferred, astroid.Instance):
@@ -1689,10 +1684,7 @@ def _is_inferred_instance(expr, klass):
16891684

16901685
@staticmethod
16911686
def _is_class_attribute(name, klass):
1692-
"""Check if the given attribute *name* is a class or instance member of the
1693-
given.
1694-
1695-
*klass*.
1687+
"""Check if 'name' is a class or instance member of 'klass'.
16961688
16971689
Returns ``True`` if the name is a property in the given klass,
16981690
``False`` otherwise.
@@ -1711,14 +1703,14 @@ def _is_class_attribute(name, klass):
17111703
return False
17121704

17131705
def visit_name(self, node: nodes.Name) -> None:
1714-
"""check if the name handle an access to a class member if so, register it."""
1706+
"""Check if the name handle an access to a class member if so, register it."""
17151707
if self._first_attrs and (
17161708
node.name == self._first_attrs[-1] or not self._first_attrs[-1]
17171709
):
17181710
self._meth_could_be_func = False
17191711

17201712
def _check_accessed_members(self, node, accessed):
1721-
"""check that accessed members are defined."""
1713+
"""Check that accessed members are defined."""
17221714
excs = ("AttributeError", "Exception", "BaseException")
17231715
for attr, nodes_lst in accessed.items():
17241716
try:
@@ -1854,8 +1846,7 @@ def _check_first_arg_config(self, first, config, node, message, method_name):
18541846
self.add_message(message, args=(method_name, valid), node=node)
18551847

18561848
def _check_bases_classes(self, node):
1857-
"""check that the given class node implements abstract methods from base
1858-
classes."""
1849+
"""Check that 'node' implements abstract methods from base classes."""
18591850

18601851
def is_abstract(method):
18611852
return method.is_abstract(pass_is_abstract=False)
@@ -1880,7 +1871,7 @@ def is_abstract(method):
18801871
self.add_message("abstract-method", node=node, args=(name, owner.name))
18811872

18821873
def _check_init(self, node):
1883-
"""check that the __init__ method call super or ancestors'__init__ method
1874+
"""Check that the __init__ method call super or ancestors'__init__ method
18841875
(unless it is used for type hinting with `typing.overload`)"""
18851876
if not self.linter.is_message_enabled(
18861877
"super-init-not-called"
@@ -1938,7 +1929,7 @@ def _check_init(self, node):
19381929
self.add_message("super-init-not-called", args=klass.name, node=node)
19391930

19401931
def _check_signature(self, method1, refmethod, class_type, cls):
1941-
"""check that the signature of the two given methods match."""
1932+
"""Check that the signature of the two given methods match."""
19421933
if not (
19431934
isinstance(method1, nodes.FunctionDef)
19441935
and isinstance(refmethod, nodes.FunctionDef)
@@ -2035,7 +2026,7 @@ def _is_mandatory_method_param(self, node):
20352026

20362027

20372028
def _ancestors_to_call(klass_node, method="__init__"):
2038-
"""return a dictionary where keys are the list of base classes providing the queried
2029+
"""Return a dictionary where keys are the list of base classes providing the queried
20392030
method, and so that should/may be called from the method node."""
20402031
to_call = {}
20412032
for base_node in klass_node.ancestors(recurs=False):

pylint/checkers/deprecated.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def visit_call(self, node: nodes.Call) -> None:
7171
"deprecated-class",
7272
)
7373
def visit_import(self, node: nodes.Import) -> None:
74-
"""triggered when an import statement is seen."""
74+
"""Triggered when an import statement is seen."""
7575
for name in (name for name, _ in node.names):
7676
self.check_deprecated_module(node, name)
7777
if "." in name:
@@ -107,7 +107,7 @@ def visit_decorators(self, node: nodes.Decorators) -> None:
107107
"deprecated-class",
108108
)
109109
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
110-
"""triggered when a from statement is seen."""
110+
"""Triggered when a from statement is seen."""
111111
basename = node.modname
112112
basename = get_import_name(node, basename)
113113
self.check_deprecated_module(node, basename)

0 commit comments

Comments
 (0)