Skip to content

Commit

Permalink
Apply pydocstring formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Jan 2, 2022
1 parent efd08b5 commit 708fbaf
Show file tree
Hide file tree
Showing 62 changed files with 221 additions and 124 deletions.
12 changes: 0 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ repos:
- id: black
args: [--safe, --quiet]
exclude: *fixtures
- repo: https://github.com/Pierre-Sassoulas/docformatter
rev: master
hooks:
- id: docformatter
# black want 88 char per line max, +3 quotes for docstring summaries
args:
[
"--in-place",
"--wrap-summaries=88",
"--wrap-descriptions=88",
]
exclude: *fixtures
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/
rev: 1.0.1
hooks:
Expand Down
3 changes: 2 additions & 1 deletion examples/custom_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

class MyRawChecker(BaseChecker):
"""Check for line continuations with '\' instead of using triple quoted string or
parenthesis."""
parenthesis.
"""

__implements__ = IRawChecker

Expand Down
3 changes: 2 additions & 1 deletion pylint/checkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def table_lines_from_stats(
stat_type: Literal["duplicated_lines", "message_types"],
) -> List[str]:
"""Get values listed in <columns> from <stats> and <old_stats>, and return a
formatted list of values, designed to be given to a ureport.Table object."""
formatted list of values, designed to be given to a ureport.Table object.
"""
lines: List[str] = []
if stat_type == "duplicated_lines":
new: List[Tuple[str, Union[str, int, float]]] = [
Expand Down
12 changes: 8 additions & 4 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
class NamingStyle:
"""It may seem counterintuitive that single naming style has multiple "accepted"
forms of regular expressions, but we need to special-case stuff like dunder names in
method names."""
method names.
"""

ANY: Pattern[str] = re.compile(".*")
CLASS_NAME_RGX: Pattern[str] = ANY
Expand Down Expand Up @@ -1300,7 +1301,8 @@ def visit_lambda(self, node: nodes.Lambda) -> None:
@utils.check_messages("dangerous-default-value")
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
"""Check function name, docstring, args, redefinition, variable names,
locals."""
locals.
"""
if node.is_method():
self.linter.stats.node_count["method"] += 1
else:
Expand Down Expand Up @@ -1363,7 +1365,8 @@ def visit_return(self, node: nodes.Return) -> None:
@utils.check_messages("unreachable")
def visit_continue(self, node: nodes.Continue) -> None:
"""Check is the node has a right sibling (if so, that's some unreachable
code)"""
code)
"""
self._check_unreachable(node)

@utils.check_messages("unreachable", "lost-exception")
Expand All @@ -1381,7 +1384,8 @@ def visit_break(self, node: nodes.Break) -> None:
@utils.check_messages("unreachable")
def visit_raise(self, node: nodes.Raise) -> None:
"""Check if the node has a right sibling (if so, that's some unreachable
code)"""
code)
"""
self._check_unreachable(node)

def _check_misplaced_format_function(self, call_node):
Expand Down
9 changes: 6 additions & 3 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,8 @@ def _check_proper_bases(self, node):

def _check_typing_final(self, node: nodes.ClassDef) -> None:
"""Detect that a class does not subclass a class decorated with
`typing.final`"""
`typing.final`
"""
if not self._py38_plus:
return
for base in node.bases:
Expand Down Expand Up @@ -1872,7 +1873,8 @@ def is_abstract(method):

def _check_init(self, node):
"""Check that the __init__ method call super or ancestors'__init__ method
(unless it is used for type hinting with `typing.overload`)"""
(unless it is used for type hinting with `typing.overload`)
"""
if not self.linter.is_message_enabled(
"super-init-not-called"
) and not self.linter.is_message_enabled("non-parent-init-called"):
Expand Down Expand Up @@ -2027,7 +2029,8 @@ def _is_mandatory_method_param(self, node):

def _ancestors_to_call(klass_node, method="__init__"):
"""Return a dictionary where keys are the list of base classes providing the queried
method, and so that should/may be called from the method node."""
method, and so that should/may be called from the method node.
"""
to_call = {}
for base_node in klass_node.ancestors(recurs=False):
try:
Expand Down
6 changes: 4 additions & 2 deletions pylint/checkers/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ def leave_classdef(self, node: nodes.ClassDef) -> None:
)
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
"""Check function name, docstring, arguments, redefinition, variable names, max
locals."""
locals.
"""
# init branch and returns counters
self._returns.append(0)
# check number of arguments
Expand Down Expand Up @@ -637,7 +638,8 @@ def visit_if(self, node: nodes.If) -> None:

def _check_boolean_expressions(self, node):
"""Go through "if" node `node` and count its boolean expressions if the 'if'
node test is a BoolOp node."""
node test is a BoolOp node.
"""
condition = node.test
if not isinstance(condition, astroid.BoolOp):
return
Expand Down
3 changes: 2 additions & 1 deletion pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ def is_line_length_check_activated(pylint_pattern_match_object) -> bool:
@staticmethod
def specific_splitlines(lines: str) -> List[str]:
"""Split lines according to universal newlines except those in a specific
sets."""
sets.
"""
unsplit_ends = {
"\v",
"\x0b",
Expand Down
6 changes: 4 additions & 2 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def _ignore_import_failure(node, modname, ignored_modules):

def _make_tree_defs(mod_files_list):
"""Get a list of 2-uple (module, list_of_files_which_import_this_module), it will
return a dictionary to represent this as a tree."""
return a dictionary to represent this as a tree.
"""
tree_defs = {}
for mod, files in mod_files_list:
node = (tree_defs, ())
Expand Down Expand Up @@ -192,7 +193,8 @@ def _make_graph(
filename: str, dep_info: Dict[str, Set[str]], sect: Section, gtype: str
):
"""Generate a dependencies graph and add some information about it in the report's
section."""
section.
"""
outputfile = _dependencies_graph(filename, dep_info)
sect.append(Paragraph((f"{gtype}imports graph has been written to {outputfile}",)))

Expand Down
6 changes: 4 additions & 2 deletions pylint/checkers/refactoring/implicit_booleaness_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def instance_has_bool(class_def: nodes.ClassDef) -> bool:
@utils.check_messages("use-implicit-booleaness-not-len")
def visit_unaryop(self, node: nodes.UnaryOp) -> None:
"""`not len(S)` must become `not S` regardless if the parent block is a test
condition or something else (boolean expression) e.g. `if not len(S):`"""
condition or something else (boolean expression) e.g. `if not len(S):`
"""
if (
isinstance(node, nodes.UnaryOp)
and node.op == "not"
Expand Down Expand Up @@ -209,7 +210,8 @@ def _check_use_implicit_booleaness_not_comparison(
@staticmethod
def base_classes_of_node(instance: nodes.ClassDef) -> List[str]:
"""Return all the classes names that a ClassDef inherit from including
'object'."""
'object'.
"""
try:
return [instance.name] + [x.name for x in instance.ancestors()]
except TypeError:
Expand Down
6 changes: 4 additions & 2 deletions pylint/checkers/refactoring/recommendation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def _check_consider_iterating_dictionary(self, node: nodes.Call) -> None:

def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
"""Add message when accessing first or last elements of a str.split() or
str.rsplit()."""
str.rsplit().
"""

# Check if call is split() or rsplit()
if not (
Expand Down Expand Up @@ -338,7 +339,8 @@ def visit_const(self, node: nodes.Const) -> None:

def _detect_replacable_format_call(self, node: nodes.Const) -> None:
"""Check whether a string is used in a call to format() or '%' and whether it
can be replaced by an f-string."""
can be replaced by an f-string.
"""
if (
isinstance(node.parent, nodes.Attribute)
and node.parent.attrname == "format"
Expand Down
9 changes: 6 additions & 3 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def _is_a_return_statement(node: nodes.Call) -> bool:

def _is_part_of_with_items(node: nodes.Call) -> bool:
"""Checks if one of the node's parents is a ``nodes.With`` node and that the node
itself is located somewhere under its ``items``."""
itself is located somewhere under its ``items``.
"""
frame = node.frame()
current = node
while current != frame:
Expand All @@ -133,7 +134,8 @@ def _is_part_of_with_items(node: nodes.Call) -> bool:

def _will_be_released_automatically(node: nodes.Call) -> bool:
"""Checks if a call that could be used in a ``with`` statement is used in an
alternative construct which would ensure that its __exit__ method is called."""
alternative construct which would ensure that its __exit__ method is called.
"""
callables_taking_care_of_exit = frozenset(
(
"contextlib._BaseExitStack.enter_context",
Expand All @@ -150,7 +152,8 @@ def _will_be_released_automatically(node: nodes.Call) -> bool:

class ConsiderUsingWithStack(NamedTuple):
"""Stack for objects that may potentially trigger a R1732 message if they are not
used in a ``with`` block later on."""
used in a ``with`` block later on.
"""

module_scope: Dict[str, nodes.NodeNG] = {}
class_scope: Dict[str, nodes.NodeNG] = {}
Expand Down
9 changes: 6 additions & 3 deletions pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class LineSpecifs(NamedTuple):
class CplSuccessiveLinesLimits:
"""This class holds a couple of SuccessiveLinesLimits objects, one for each file
compared, and a counter on the number of common lines between both stripped lines
collections extracted from both files."""
collections extracted from both files.
"""

__slots__ = ("first_file", "second_file", "effective_cmn_lines_nb")

Expand All @@ -135,7 +136,8 @@ def __init__(

class LinesChunk:
"""The LinesChunk object computes and stores the hash of some consecutive stripped
lines of a lineset."""
lines of a lineset.
"""

__slots__ = ("_fileid", "_index", "_hash")

Expand Down Expand Up @@ -597,7 +599,8 @@ def _get_functions(
functions: List[nodes.NodeNG], tree: nodes.NodeNG
) -> List[nodes.NodeNG]:
"""Recursively get all functions including nested in the classes from the
tree."""
tree.
"""

for node in tree.body:
if isinstance(node, (nodes.FunctionDef, nodes.AsyncFunctionDef)):
Expand Down
3 changes: 2 additions & 1 deletion pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class SphinxDirectives(RegExFilter):

class ForwardSlashChunker(Chunker):
"""This chunker allows splitting words like 'before/after' into 'before' and
'after'."""
'after'.
"""

def next(self):
while True:
Expand Down
9 changes: 6 additions & 3 deletions pylint/checkers/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@

def get_access_path(key, parts):
"""Given a list of format specifiers, returns the final access path (e.g.
a.b.c[0][1])."""
a.b.c[0][1]).
"""
path = []
for is_attribute, specifier in parts:
if is_attribute:
Expand Down Expand Up @@ -256,7 +257,8 @@ def arg_matches_format_type(arg_type, format_type):

class StringFormatChecker(BaseChecker):
"""Checks string formatting operations to ensure that the format string is valid and
the arguments match the format string."""
the arguments match the format string.
"""

__implements__ = (IAstroidChecker,)
name = "string"
Expand Down Expand Up @@ -538,7 +540,8 @@ def _check_new_format(self, node, func):

def _check_new_format_specifiers(self, node, fields, named):
"""Check attribute and index access in the format string ("{0.a}" and
"{0[a]}")."""
"{0[a]}").
"""
for key, specifiers in fields:
# Obtain the argument. If it can't be obtained
# or inferred, skip this check.
Expand Down
12 changes: 8 additions & 4 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,8 @@ def visit_assign(self, node: nodes.Assign) -> None:

def _check_assignment_from_function_call(self, node):
"""Check that if assigning to a function call, the function is possibly
returning something valuable."""
returning something valuable.
"""
if not isinstance(node.value, nodes.Call):
return

Expand Down Expand Up @@ -1209,7 +1210,8 @@ def _check_dundername_is_string(self, node):

def _check_uninferable_call(self, node):
"""Check that the given uninferable Call node does not call an actual
function."""
function.
"""
if not isinstance(node.func, nodes.Attribute):
return

Expand Down Expand Up @@ -1310,7 +1312,8 @@ def _check_isinstance_args(self, node):
def visit_call(self, node: nodes.Call) -> None:
"""Check that called functions/methods are inferred to callable objects, and
that the arguments passed to the function match the parameters in the inferred
function's definition."""
function's definition.
"""
called = safe_infer(node.func)

self._check_not_callable(node, called)
Expand Down Expand Up @@ -1508,7 +1511,8 @@ def _keyword_argument_is_in_all_decorator_returns(
func: nodes.FunctionDef, keyword: str
) -> bool:
"""Check if the keyword argument exists in all signatures of the return values
of all decorators of the function."""
of all decorators of the function.
"""
if not func.decorators:
return False

Expand Down
6 changes: 4 additions & 2 deletions pylint/checkers/unsupported_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

class UnsupportedVersionChecker(BaseChecker):
"""Checker for features that are not supported by all python versions indicated by
the py-version setting."""
the py-version setting.
"""

__implements__ = (IAstroidChecker,)
name = "unsupported_version"
Expand Down Expand Up @@ -66,7 +67,8 @@ def visit_decorators(self, node: nodes.Decorators) -> None:

def _check_typing_final(self, node: nodes.Decorators) -> None:
"""Add a message when the `typing.final` decorator is used and the py- version
is lower than 3.8."""
is lower than 3.8.
"""
if self._py38_plus:
return

Expand Down
Loading

0 comments on commit 708fbaf

Please sign in to comment.