Skip to content

Commit

Permalink
[ruff] Activate pydocstyle and fix existing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed May 4, 2024
1 parent 5261fcc commit df5533f
Show file tree
Hide file tree
Showing 41 changed files with 72 additions and 81 deletions.
4 changes: 2 additions & 2 deletions examples/custom_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


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

name = "custom_raw"
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/base/comparison_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def _check_singleton_comparison(
checking_for_absence: bool = False,
) -> None:
"""Check if == or != is being used to compare a singleton value."""

if utils.is_singleton_const(left_value):
singleton, other_value = left_value.value, right_value
elif utils.is_singleton_const(right_value):
Expand Down
3 changes: 0 additions & 3 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ def _is_attribute_property(name: str, klass: nodes.ClassDef) -> bool:
Returns ``True`` if the name is a property in the given klass,
``False`` otherwise.
"""

try:
attributes = klass.getattr(name)
except astroid.NotFoundError:
Expand Down Expand Up @@ -748,7 +747,6 @@ def __init__(self) -> None:

def set_accessed(self, node: _AccessNodes) -> None:
"""Set the given node as accessed."""

frame = node_frame_class(node)
if frame is None:
# The node does not live in a class.
Expand Down Expand Up @@ -1946,7 +1944,6 @@ def _is_class_or_instance_attribute(name: str, klass: nodes.ClassDef) -> bool:
Returns ``True`` if the name is a property in the given klass,
``False`` otherwise.
"""

if utils.is_class_attr(name, klass):
return True

Expand Down
3 changes: 0 additions & 3 deletions pylint/checkers/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def check_deprecated_method(self, node: nodes.Call, inferred: nodes.NodeNG) -> N
This method should be called from the checker implementing this mixin.
"""

# Reject nodes which aren't of interest to us.
if not isinstance(inferred, ACCEPTABLE_NODES):
return
Expand Down Expand Up @@ -272,7 +271,6 @@ def check_deprecated_class(
self, node: nodes.NodeNG, mod_name: str, class_names: Iterable[str]
) -> None:
"""Checks if the class is deprecated."""

for class_name in class_names:
if class_name in self.deprecated_classes(mod_name):
self.add_message(
Expand All @@ -281,7 +279,6 @@ def check_deprecated_class(

def check_deprecated_class_in_call(self, node: nodes.Call) -> None:
"""Checks if call the deprecated class."""

if isinstance(node.func, nodes.Attribute) and isinstance(
node.func.expr, nodes.Name
):
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@

def _is_exempt_from_public_methods(node: astroid.ClassDef) -> bool:
"""Check if a class is exempt from too-few-public-methods."""

# If it's a typing.Namedtuple, typing.TypedDict or an Enum
for ancestor in node.ancestors():
if is_enum(ancestor):
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ def _add_imported_module(self, node: ImportNode, importedmodname: str) -> None:

def _check_preferred_module(self, node: ImportNode, mod_path: str) -> None:
"""Check if the module has a preferred replacement."""

mod_compare = [mod_path]
# build a comparison list of possible names using importfrom
if isinstance(node, astroid.nodes.node_classes.ImportFrom):
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/non_ascii_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class NonAsciiNameChecker(base_checker.BaseChecker):

def _check_name(self, node_type: str, name: str | None, node: nodes.NodeNG) -> None:
"""Check whether a name is using non-ASCII characters."""

if name is None:
# For some nodes i.e. *kwargs from a dict, the name will be empty
return
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/refactoring/recommendation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ 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().
"""

# Check if call is split() or rsplit()
if not (
isinstance(node.func, nodes.Attribute)
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ def _check_simplifiable_if(self, node: nodes.If) -> None:
the result of the statement's test, then this can be reduced
to `bool(test)` without losing any functionality.
"""

if self._is_actual_elif(node):
# Not interested in if statements with multiple branches.
return
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ def _get_functions(
"""Recursively get all functions including nested in the classes from the
tree.
"""

for node in tree.body:
if isinstance(node, (nodes.FunctionDef, nodes.AsyncFunctionDef)):
functions.append(node)
Expand Down
3 changes: 0 additions & 3 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,6 @@ def _get_nomember_msgid_hint(
)
def visit_assign(self, node: nodes.Assign) -> None:
"""Process assignments in the AST."""

self._check_assignment_from_function_call(node)
self._check_dundername_is_string(node)

Expand Down Expand Up @@ -1309,7 +1308,6 @@ def _is_builtin_no_return(node: nodes.Assign) -> bool:

def _check_dundername_is_string(self, node: nodes.Assign) -> None:
"""Check a string is assigned to self.__name__."""

# Check the left-hand side of the assignment is <something>.__name__
lhs = node.targets[0]
if not isinstance(lhs, nodes.AssignAttr):
Expand Down Expand Up @@ -1926,7 +1924,6 @@ def visit_with(self, node: nodes.With) -> None:
@only_required_for_messages("invalid-unary-operand-type")
def visit_unaryop(self, node: nodes.UnaryOp) -> None:
"""Detect TypeErrors for unary operands."""

for error in node.type_errors():
# Let the error customize its output.
self.add_message("invalid-unary-operand-type", args=str(error), node=node)
Expand Down
3 changes: 1 addition & 2 deletions pylint/checkers/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def _map_positions_to_result(
Also takes care of encodings for which the length of an encoded code point does not
default to 8 Bit.
"""

result: dict[int, _BadChar] = {}

for search_for, char in search_dict.items():
Expand Down Expand Up @@ -248,7 +247,7 @@ def _cached_encode_search(string: str, encoding: str) -> bytes:


def _fix_utf16_32_line_stream(steam: Iterable[bytes], codec: str) -> Iterable[bytes]:
"""Handle line ending for UTF16 and UTF32 correctly.
r"""Handle line ending for UTF16 and UTF32 correctly.
Currently, Python simply strips the required zeros after \n after the
line ending. Leading to lines that can't be decoded properly
Expand Down
3 changes: 0 additions & 3 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,6 @@ def node_type(node: nodes.NodeNG) -> SuccessfulInferenceResult | None:

def is_registered_in_singledispatch_function(node: nodes.FunctionDef) -> bool:
"""Check if the given function node is a singledispatch function."""

singledispatch_qnames = (
"functools.singledispatch",
"singledispatch.singledispatch",
Expand Down Expand Up @@ -1540,7 +1539,6 @@ def find_inferred_fn_from_register(node: nodes.NodeNG) -> nodes.FunctionDef | No

def is_registered_in_singledispatchmethod_function(node: nodes.FunctionDef) -> bool:
"""Check if the given function node is a singledispatchmethod function."""

singledispatchmethod_qnames = (
"functools.singledispatchmethod",
"singledispatch.singledispatchmethod",
Expand Down Expand Up @@ -2276,7 +2274,6 @@ def is_enum_member(node: nodes.AssignName) -> bool:
"""Return `True` if `node` is an Enum member (is an item of the
`__members__` container).
"""

frame = node.frame()
if (
not isinstance(frame, nodes.ClassDef)
Expand Down
1 change: 0 additions & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ def _check_loop_finishes_via_except(
the loop can depend on it being assigned.
Example:
for _ in range(3):
try:
do_something()
Expand Down
2 changes: 0 additions & 2 deletions pylint/extensions/empty_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

def is_line_commented(line: bytes) -> bool:
"""Checks if a `# symbol that is not part of a string was found in line."""

comment_idx = line.find(b"#")
if comment_idx == -1:
return False
Expand All @@ -27,7 +26,6 @@ def is_line_commented(line: bytes) -> bool:

def comment_part_of_string(line: bytes, comment_idx: int) -> bool:
"""Checks if the symbol at comment_idx is part of a string."""

if (
line[:comment_idx].count(b"'") % 2 == 1
and line[comment_idx:].count(b"'") % 2 == 1
Expand Down
10 changes: 5 additions & 5 deletions pylint/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

"""Pylint [options] modules_or_packages.
Check that module(s) satisfy a coding standard (and more !).
Check that module(s) satisfy a coding standard (and more !).
pylint --help
pylint --help
Display this help message and exit.
Display this help message and exit.
pylint --help-msg <msg-id>[,<msg-id>]
pylint --help-msg <msg-id>[,<msg-id>]
Display help messages about given message identifiers and exit.
Display help messages about given message identifiers and exit.
"""
import sys

Expand Down
1 change: 0 additions & 1 deletion pylint/pyreverse/diadefslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def get_diadefs(self, project: Project, linker: Linker) -> list[ClassDiagram]:
:returns: The list of diagram definitions
:rtype: list(:class:`pylint.pyreverse.diagrams.ClassDiagram`)
"""

# read and interpret diagram definitions (Diadefs)
diagrams = []
generator = ClassDiadefGenerator(linker, self)
Expand Down
1 change: 0 additions & 1 deletion pylint/pyreverse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ def infer_node(node: nodes.AssignAttr | nodes.AssignName) -> set[InferenceResult
"""Return a set containing the node annotation if it exists
otherwise return a set of the inferred types using the NodeNG.infer method.
"""

ann = get_annotation(node)
try:
if ann:
Expand Down
5 changes: 3 additions & 2 deletions pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def register_plugins(linter: PyLinter, directory: str) -> None:


def _splitstrip(string: str, sep: str = ",") -> list[str]:
"""Return a list of stripped string by splitting the string given as
r"""Return a list of stripped string by splitting the string given as
argument on `sep` (',' by default), empty strings are discarded.
>>> _splitstrip('a, b, c , 4,,')
Expand Down Expand Up @@ -254,7 +254,8 @@ def _check_csv(value: list[str] | tuple[str] | str) -> Sequence[str]:

def _check_regexp_csv(value: list[str] | tuple[str] | str) -> Iterable[str]:
r"""Split a comma-separated list of regexps, taking care to avoid splitting
a regex employing a comma as quantifier, as in `\d{1,2}`."""
a regex employing a comma as quantifier, as in `\d{1,2}`.
"""
if isinstance(value, (list, tuple)):
yield from value
else:
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ line-length = 115
[tool.ruff.lint]
select = [
"B", # bugbear
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"I", # isort
Expand All @@ -159,5 +160,19 @@ select = [

ignore = [
"B905", # `zip()` without an explicit `strict=` parameter
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Missing docstring in `__init__`
"D205", # 1 blank line required between summary line and description
"D400", # First line should end with a period
"D401", # First line of docstring should be in imperative mood
"RUF012", # mutable default values in class attributes
]

[tool.ruff.lint.pydocstyle]
convention = "pep257"
1 change: 0 additions & 1 deletion tests/checkers/unittest_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_too_many_ancestors_ignored_parents_are_skipped(self) -> None:
"""Make sure that classes listed in ``ignored-parents`` aren't counted
by the too-many-ancestors message.
"""

node = astroid.extract_node(
"""
class Aaaa(object):
Expand Down
2 changes: 1 addition & 1 deletion tests/checkers/unittest_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_encoding_token(self) -> None:

def test_disable_global_option_end_of_line() -> None:
"""Test for issue with disabling tokenizer messages
that extend beyond the scope of the ast tokens
that extend beyond the scope of the ast tokens.
"""
file_ = tempfile.NamedTemporaryFile("w", delete=False)
with file_:
Expand Down
5 changes: 1 addition & 4 deletions tests/checkers/unittest_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def test_wildcard_import_non_init(self) -> None:

@staticmethod
def test_preferred_module(capsys: CaptureFixture[str]) -> None:
"""
Tests preferred-module configuration option
"""
"""Tests preferred-module configuration option."""
# test preferred-modules case with base module import
Run(
[
Expand Down Expand Up @@ -212,7 +210,6 @@ def test_preferred_module(capsys: CaptureFixture[str]) -> None:
@staticmethod
def test_allow_reexport_package(capsys: CaptureFixture[str]) -> None:
"""Test --allow-reexport-from-package option."""

# Option disabled - useless-import-alias should always be emitted
Run(
[
Expand Down
3 changes: 2 additions & 1 deletion tests/checkers/unittest_spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def test_skip_sphinx_directives_2(self) -> None:
)
def test_tool_directives_handling(self, prefix: str, suffix: str) -> None:
"""We're not raising when the directive is at the beginning of comments,
but we raise if a directive appears later in comment."""
but we raise if a directive appears later in comment.
"""
full_comment = f"# {prefix}{suffix} {prefix}"
args = (
prefix,
Expand Down
2 changes: 1 addition & 1 deletion tests/checkers/unittest_unicode/unittest_bad_chars.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_bad_chars_that_would_currently_crash_python(
codec_and_msg: tuple[str, tuple[pylint.testutils.MessageTest]],
) -> None:
"""Special test for a file containing chars that lead to
Python or Astroid crashes (which causes Pylint to exit early)
Python or Astroid crashes (which causes Pylint to exit early).
"""
codec, start_msg = codec_and_msg
# Create file that will fail loading in astroid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class TestBidirectionalUnicodeChecker(pylint.testutils.CheckerTestCase):

def test_finds_bidirectional_unicode_that_currently_not_parsed(self) -> None:
"""Test an example from https://github.com/nickboucher/trojan-source/tree/main/Python
that is currently not working Python but producing a syntax error
that is currently not working Python but producing a syntax error.
So we test this to make sure it stays like this
"""

test_file = UNICODE_TESTS / "invisible_function.txt"

with pytest.raises(astroid.AstroidSyntaxError):
Expand Down
4 changes: 2 additions & 2 deletions tests/checkers/unittest_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class MyObject(object):

def test_nested_lambda(self) -> None:
"""Make sure variables from parent lambdas
aren't noted as undefined
aren't noted as undefined.
https://github.com/pylint-dev/pylint/issues/760
"""
Expand All @@ -179,7 +179,7 @@ def test_nested_lambda(self) -> None:
@set_config(ignored_argument_names=re.compile("arg"))
def test_ignored_argument_names_no_message(self) -> None:
"""Make sure is_ignored_argument_names properly ignores
function arguments
function arguments.
"""
node = astroid.parse(
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_argparse_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt

"""Test for the (new) implementation of option parsing with argparse"""
"""Test for the (new) implementation of option parsing with argparse."""

import re
from os.path import abspath, dirname, join
Expand Down

0 comments on commit df5533f

Please sign in to comment.