summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOllie <46904826+ollie-iterators@users.noreply.github.com>2023-02-25 16:12:29 -0500
committerGitHub <noreply@github.com>2023-02-25 22:12:29 +0100
commit02030cf52dbbed3a8bb7c14c4d6158427635cee5 (patch)
tree5c1006b9695be3a05870070c30f55784172e068a
parentc785e3edb82683e50d5d370c1c4e992ebda036a0 (diff)
downloadpylint-git-02030cf52dbbed3a8bb7c14c4d6158427635cee5.tar.gz
Fixing some too long lines (#8339)
* Changing flake8 max-line-length to 120 Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r--pylint/checkers/base/name_checker/naming_style.py5
-rw-r--r--pylint/checkers/classes/class_checker.py6
-rw-r--r--pylint/checkers/refactoring/refactoring_checker.py26
-rw-r--r--pylint/checkers/similar.py6
-rw-r--r--pylint/checkers/unicode.py5
-rw-r--r--pylint/config/config_file_parser.py4
-rw-r--r--pylint/extensions/confusing_elif.py3
-rw-r--r--pylint/extensions/private_import.py9
-rw-r--r--pylint/lint/pylinter.py12
-rw-r--r--pylint/reporters/text.py3
-rw-r--r--script/check_newsfragments.py5
-rw-r--r--setup.cfg2
-rw-r--r--tests/checkers/unittest_utils.py10
-rw-r--r--tests/config/test_config.py8
-rw-r--r--tests/config/test_functional_config_loading.py16
-rw-r--r--tests/test_self.py4
-rw-r--r--tests/test_similar.py3
17 files changed, 79 insertions, 48 deletions
diff --git a/pylint/checkers/base/name_checker/naming_style.py b/pylint/checkers/base/name_checker/naming_style.py
index 3b7833049..bfe6f77d3 100644
--- a/pylint/checkers/base/name_checker/naming_style.py
+++ b/pylint/checkers/base/name_checker/naming_style.py
@@ -149,7 +149,10 @@ def _create_naming_options() -> Options:
help_msg = f"Regular expression matching correct {human_readable_name} names. "
if name_type in KNOWN_NAME_TYPES_WITH_STYLE:
help_msg += f"Overrides {name_type_hyphened}-naming-style. "
- help_msg += f"If left empty, {human_readable_name} names will be checked with the set naming style."
+ help_msg += (
+ f"If left empty, {human_readable_name} names will be checked "
+ "with the set naming style."
+ )
# Add style option for names that support it
if name_type in KNOWN_NAME_TYPES_WITH_STYLE:
diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py
index e66e543f2..fe29c9d60 100644
--- a/pylint/checkers/classes/class_checker.py
+++ b/pylint/checkers/classes/class_checker.py
@@ -958,7 +958,8 @@ a metaclass class method.",
):
continue
for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
- # Check for cases where the functions are used as a variable instead of as a method call
+ # Check for cases where the functions are used as a variable instead of as a
+ # method call
if isinstance(child, nodes.Name) and child.name == function_def.name:
break
if isinstance(child, nodes.Attribute):
@@ -1951,7 +1952,8 @@ a metaclass class method.",
return
self._first_attrs[-1] = None
elif "builtins.staticmethod" in node.decoratornames():
- # Check if there is a decorator which is not named `staticmethod` but is assigned to one.
+ # Check if there is a decorator which is not named `staticmethod`
+ # but is assigned to one.
return
# class / regular method with no args
elif not (
diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py
index 5aaedf794..b3e48f31e 100644
--- a/pylint/checkers/refactoring/refactoring_checker.py
+++ b/pylint/checkers/refactoring/refactoring_checker.py
@@ -460,8 +460,9 @@ class RefactoringChecker(checkers.BaseTokenChecker):
"R1732": (
"Consider using 'with' for resource-allocating operations",
"consider-using-with",
- "Emitted if a resource-allocating assignment or call may be replaced by a 'with' block. "
- "By using 'with' the release of the allocated resources is ensured even in the case of an exception.",
+ "Emitted if a resource-allocating assignment or call may be replaced by a 'with' block."
+ "By using 'with' the release of the allocated resources is ensured even in the case "
+ "of an exception.",
),
"R1733": (
"Unnecessary dictionary index lookup, use '%s' instead",
@@ -713,8 +714,9 @@ class RefactoringChecker(checkers.BaseTokenChecker):
for var, names in node.items:
if isinstance(var, nodes.Name):
for stack in self._consider_using_with_stack:
- # We don't need to restrict the stacks we search to the current scope and outer scopes,
- # as e.g. the function_scope stack will be empty when we check a ``with`` on the class level.
+ # We don't need to restrict the stacks we search to the current scope and
+ # outer scopes, as e.g. the function_scope stack will be empty when we
+ # check a ``with`` on the class level.
if var.name in stack:
del stack[var.name]
break
@@ -1118,7 +1120,8 @@ class RefactoringChecker(checkers.BaseTokenChecker):
def _check_quit_exit_call(self, node: nodes.Call) -> None:
if isinstance(node.func, nodes.Name) and node.func.name in BUILTIN_EXIT_FUNCS:
- # If we have `exit` imported from `sys` in the current or global scope, exempt this instance.
+ # If we have `exit` imported from `sys` in the current or global scope,
+ # exempt this instance.
local_scope = node.scope()
if self._has_exit_in_scope(local_scope) or self._has_exit_in_scope(
node.root()
@@ -1553,7 +1556,8 @@ class RefactoringChecker(checkers.BaseTokenChecker):
def _append_context_managers_to_stack(self, node: nodes.Assign) -> None:
if _is_inside_context_manager(node):
- # if we are inside a context manager itself, we assume that it will handle the resource management itself.
+ # if we are inside a context manager itself, we assume that it will handle
+ # the resource management itself.
return
if isinstance(node.targets[0], (nodes.Tuple, nodes.List, nodes.Set)):
assignees = node.targets[0].elts
@@ -1600,9 +1604,10 @@ class RefactoringChecker(checkers.BaseTokenChecker):
def _check_consider_using_with(self, node: nodes.Call) -> None:
if _is_inside_context_manager(node) or _is_a_return_statement(node):
- # If we are inside a context manager itself, we assume that it will handle the resource management itself.
- # If the node is a child of a return, we assume that the caller knows he is getting a context manager
- # he should use properly (i.e. in a ``with``).
+ # If we are inside a context manager itself, we assume that it will handle the
+ # resource management itself.
+ # If the node is a child of a return, we assume that the caller knows he is getting
+ # a context manager he should use properly (i.e. in a ``with``).
return
if (
node
@@ -1610,7 +1615,8 @@ class RefactoringChecker(checkers.BaseTokenChecker):
node.frame(future=True)
).values()
):
- # the result of this call was already assigned to a variable and will be checked when leaving the scope.
+ # the result of this call was already assigned to a variable and will be
+ # checked when leaving the scope.
return
inferred = utils.safe_infer(node.func)
if not inferred or not isinstance(
diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py
index bc485a981..2cfba16bf 100644
--- a/pylint/checkers/similar.py
+++ b/pylint/checkers/similar.py
@@ -377,7 +377,8 @@ class Similar:
raise ValueError
readlines = decoding_stream(stream, encoding).readlines
else:
- readlines = stream.readlines # type: ignore[assignment] # hint parameter is incorrectly typed as non-optional
+ # hint parameter is incorrectly typed as non-optional
+ readlines = stream.readlines # type: ignore[assignment]
try:
lines = readlines()
@@ -590,7 +591,8 @@ def stripped_lines(
:param ignore_docstrings: if true, any line that is a docstring is removed from the result
:param ignore_imports: if true, any line that is an import is removed from the result
:param ignore_signatures: if true, any line that is part of a function signature is removed from the result
- :param line_enabled_callback: If called with "R0801" and a line number, a return value of False will disregard the line
+ :param line_enabled_callback: If called with "R0801" and a line number, a return value of False will disregard
+ the line
:return: the collection of line/line number/line type tuples
"""
if ignore_imports or ignore_signatures:
diff --git a/pylint/checkers/unicode.py b/pylint/checkers/unicode.py
index 6d7b25395..3e2bccfa5 100644
--- a/pylint/checkers/unicode.py
+++ b/pylint/checkers/unicode.py
@@ -330,7 +330,7 @@ class UnicodeChecker(checkers.BaseRawFileChecker):
"For compatibility use UTF-8 instead of UTF-16/UTF-32. "
"See also https://bugs.python.org/issue1503789 for a history "
"of this issue. And "
- "https://softwareengineering.stackexchange.com/questions/102205/should-utf-16-be-considered-harmful "
+ "https://softwareengineering.stackexchange.com/questions/102205/"
"for some possible problems when using UTF-16 for instance."
),
),
@@ -347,7 +347,8 @@ class UnicodeChecker(checkers.BaseRawFileChecker):
"So can you trust this code? "
"Are you sure it displayed correctly in all editors? "
"If you did not write it or your language is not RTL,"
- " remove the special characters, as they could be used to trick you into executing code, "
+ " remove the special characters, as they could be used to trick you into "
+ "executing code, "
"that does something else than what it looks like.\n"
"More Information:\n"
"https://en.wikipedia.org/wiki/Bidirectional_text\n"
diff --git a/pylint/config/config_file_parser.py b/pylint/config/config_file_parser.py
index b6809d984..019f9b738 100644
--- a/pylint/config/config_file_parser.py
+++ b/pylint/config/config_file_parser.py
@@ -49,8 +49,8 @@ class _ConfigurationFileParser:
# TODO: 3.0: Remove deprecated handling of master, only allow 'pylint.' sections
warnings.warn(
"The use of 'MASTER' or 'master' as configuration section for pylint "
- "has been deprecated, as it's bad practice to not start sections titles with the "
- "tool name. Please use 'pylint.main' instead.",
+ "has been deprecated, as it's bad practice to not start sections titles "
+ "with the tool name. Please use 'pylint.main' instead.",
UserWarning,
)
else:
diff --git a/pylint/extensions/confusing_elif.py b/pylint/extensions/confusing_elif.py
index 174f464ac..d16d6c60a 100644
--- a/pylint/extensions/confusing_elif.py
+++ b/pylint/extensions/confusing_elif.py
@@ -23,7 +23,8 @@ class ConfusingConsecutiveElifChecker(BaseChecker):
name = "confusing_elif"
msgs = {
"R5601": (
- "Consecutive elif with differing indentation level, consider creating a function to separate the inner elif",
+ "Consecutive elif with differing indentation level, consider creating a function to separate the inner"
+ " elif",
"confusing-consecutive-elif",
"Used when an elif statement follows right after an indented block which itself ends with if or elif. "
"It may not be ovious if the elif statement was willingly or mistakenly unindented. "
diff --git a/pylint/extensions/private_import.py b/pylint/extensions/private_import.py
index fb4458e54..01d800c94 100644
--- a/pylint/extensions/private_import.py
+++ b/pylint/extensions/private_import.py
@@ -64,7 +64,8 @@ class PrivateImportChecker(BaseChecker):
names = [n[0] for n in node.names]
- # Check the imported objects first. If they are all valid type annotations, the package can be private
+ # Check the imported objects first. If they are all valid type annotations,
+ # the package can be private
private_names = self._get_type_annotation_names(node, names)
if not private_names:
return
@@ -139,7 +140,8 @@ class PrivateImportChecker(BaseChecker):
for name in node.locals:
# If we find a private type annotation, make sure we do not mask illegal usages
private_name = None
- # All the assignments using this variable that we might have to check for illegal usages later
+ # All the assignments using this variable that we might have to check for
+ # illegal usages later
name_assignments = []
for usage_node in node.locals[name]:
if isinstance(usage_node, nodes.AssignName) and isinstance(
@@ -205,7 +207,8 @@ class PrivateImportChecker(BaseChecker):
node.value, all_used_type_annotations
)
if isinstance(node, nodes.Attribute):
- # An attribute is a type like `pylint.lint.pylinter`. node.expr is the next level up, could be another attribute
+ # An attribute is a type like `pylint.lint.pylinter`. node.expr is the next level
+ # up, could be another attribute
return self._populate_type_annotations_annotation(
node.expr, all_used_type_annotations
)
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 5b749d5b2..863076f8f 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -227,7 +227,8 @@ MSGS: dict[str, MessageDefinitionTuple] = {
"E0014": (
"Out-of-place setting encountered in top level configuration-section '%s' : '%s'",
"bad-configuration-section",
- "Used when we detect a setting in the top level of a toml configuration that shouldn't be there.",
+ "Used when we detect a setting in the top level of a toml configuration that"
+ " shouldn't be there.",
{"scope": WarningScope.LINE},
),
"E0015": (
@@ -794,7 +795,8 @@ class PyLinter(
:param FileItem file: data about the file
:param nodes.Module module: the ast module to lint
- :param Callable check_astroid_module: callable checking an AST taking the following arguments
+ :param Callable check_astroid_module: callable checking an AST taking the following
+ arguments
- ast: AST of the module
:raises AstroidError: for any failures stemming from astroid
"""
@@ -826,10 +828,12 @@ class PyLinter(
"""Check a file using the passed utility functions (get_ast and
check_astroid_module).
- :param callable get_ast: callable returning AST from defined file taking the following arguments
+ :param callable get_ast: callable returning AST from defined file taking the
+ following arguments
- filepath: path to the file to check
- name: Python module name
- :param callable check_astroid_module: callable checking an AST taking the following arguments
+ :param callable check_astroid_module: callable checking an AST taking the following
+ arguments
- ast: AST of the module
:param FileItem file: data about the file
:raises AstroidError: for any failures stemming from astroid
diff --git a/pylint/reporters/text.py b/pylint/reporters/text.py
index bc11ac4fa..168bb1496 100644
--- a/pylint/reporters/text.py
+++ b/pylint/reporters/text.py
@@ -273,7 +273,8 @@ class ColorizedTextReporter(TextReporter):
) = None,
) -> None:
super().__init__(output)
- # TODO: 3.0: Remove deprecated typing and only accept ColorMappingDict as color_mapping parameter
+ # TODO: 3.0: Remove deprecated typing and only accept ColorMappingDict as
+ # color_mapping parameter
if color_mapping and not isinstance(
list(color_mapping.values())[0], MessageStyle
):
diff --git a/script/check_newsfragments.py b/script/check_newsfragments.py
index 62560c9da..b840d9da0 100644
--- a/script/check_newsfragments.py
+++ b/script/check_newsfragments.py
@@ -37,7 +37,10 @@ VALID_FILE_TYPE = frozenset(
]
)
ISSUES_KEYWORDS = "|".join(VALID_ISSUES_KEYWORDS)
-VALID_CHANGELOG_PATTERN = rf"(?P<description>(.*\n)*(.*\.\n))\n(?P<ref>({ISSUES_KEYWORDS}) (PyCQA/astroid)?#(?P<issue>\d+))"
+VALID_CHANGELOG_PATTERN = (
+ rf"(?P<description>(.*\n)*(.*\.\n))\n(?P<ref>({ISSUES_KEYWORDS})"
+ r" (PyCQA/astroid)?#(?P<issue>\d+))"
+)
VALID_CHANGELOG_COMPILED_PATTERN: Pattern[str] = re.compile(
VALID_CHANGELOG_PATTERN, flags=re.MULTILINE
)
diff --git a/setup.cfg b/setup.cfg
index e4c696c4c..80fced5a2 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -19,7 +19,7 @@ ignore =
B028,
# Flake8 is less lenient than pylint and does not make any exceptions
# (for docstrings, strings and comments in particular).
-max-line-length=125
+max-line-length=120
# Required for flake8-typing-imports (v1.12.0)
# The plugin doesn't yet read the value from pyproject.toml
min_python_version = 3.7.2
diff --git a/tests/checkers/unittest_utils.py b/tests/checkers/unittest_utils.py
index 2f0bf0e08..b2cbcb590 100644
--- a/tests/checkers/unittest_utils.py
+++ b/tests/checkers/unittest_utils.py
@@ -484,12 +484,14 @@ def test_deprecation_check_messages() -> None:
def visit_assname(self, node: nodes.NodeNG) -> None:
pass
- assert len(records) == 1
- assert (
- records[0].message.args[0]
- == "utils.check_messages will be removed in favour of calling utils.only_required_for_messages in pylint 3.0"
+ deprecationMessage = (
+ "utils.check_messages will be removed in "
+ "favour of calling utils.only_required_for_messages in pylint 3.0"
)
+ assert len(records) == 1
+ assert records[0].message.args[0] == deprecationMessage
+
def test_is_typing_member() -> None:
code = astroid.extract_node(
diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index be28d324b..5eab597fd 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -121,10 +121,12 @@ def test_regex_error(capsys: CaptureFixture) -> None:
exit=False,
)
output = capsys.readouterr()
- assert (
- r"Error in provided regular expression: [\p{Han}a-z_][\p{Han}a-z0-9_]{2,30}$ beginning at index 1: bad escape \p"
- in output.err
+
+ assertString = (
+ r"Error in provided regular expression: [\p{Han}a-z_][\p{Han}a-z0-9_]{2,30}$ "
+ r"beginning at index 1: bad escape \p"
)
+ assert assertString in output.err
def test_csv_regex_error(capsys: CaptureFixture) -> None:
diff --git a/tests/config/test_functional_config_loading.py b/tests/config/test_functional_config_loading.py
index 432bdc1a1..d5a2ba7ca 100644
--- a/tests/config/test_functional_config_loading.py
+++ b/tests/config/test_functional_config_loading.py
@@ -6,15 +6,15 @@
files by providing a file with the appropriate extension in the ``tests/config/functional``
directory.
-Let's say you have a regression_list_crash.toml file to test. Then, if there is an error in the conf,
-add ``regression_list_crash.out`` alongside your file with the expected output of pylint in it. Use
-``{relpath}`` and ``{abspath}`` for the path of the file. The exit code will have to be 2 (error)
-if this file exists.
+Let's say you have a regression_list_crash.toml file to test. Then, if there is an error in the
+conf, add ``regression_list_crash.out`` alongside your file with the expected output of pylint in
+it. Use ``{relpath}`` and ``{abspath}`` for the path of the file. The exit code will have to be 2
+ (error) if this file exists.
-You must also define a ``regression_list_crash.result.json`` if you want to check the parsed configuration.
-This file will be loaded as a dict and will override the default value of the default pylint
-configuration. If you need to append or remove a value use the special key ``"functional_append"``
-and ``"functional_remove":``. Check the existing code for examples.
+You must also define a ``regression_list_crash.result.json`` if you want to check the parsed
+configuration. This file will be loaded as a dict and will override the default value of the
+default pylint configuration. If you need to append or remove a value use the special key
+``"functional_append"`` and ``"functional_remove":``. Check the existing code for examples.
"""
# pylint: disable=redefined-outer-name
diff --git a/tests/test_self.py b/tests/test_self.py
index 7dbbcf565..07c2a2f0b 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -716,8 +716,8 @@ a.py:1:4: E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-er
@pytest.mark.parametrize(
"fu_score,fo_msgs,fname,out",
[
- # Essentially same test cases as --fail-under, but run with/without a detected issue code
- # missing-function-docstring (C0116) is issue in both files
+ # Essentially same test cases as --fail-under, but run with/without a detected
+ # issue code missing-function-docstring (C0116) is issue in both files
# --fail-under should be irrelevant as missing-function-docstring is hit
(-10, "missing-function-docstring", "fail_under_plus7_5.py", 16),
(6, "missing-function-docstring", "fail_under_plus7_5.py", 16),
diff --git a/tests/test_similar.py b/tests/test_similar.py
index 5558b70e7..051bc4b27 100644
--- a/tests/test_similar.py
+++ b/tests/test_similar.py
@@ -207,7 +207,8 @@ class TestSimilarCodeChecker:
)
def test_duplicate_code_raw_strings_disable_scope_function(self) -> None:
- """Tests disabling duplicate-code at an inner scope level with another scope with similarity."""
+ """Tests disabling duplicate-code at an inner scope level with another scope with
+ similarity."""
path = join(DATA, "raw_strings_disable_scope_second_function")
expected_output = "Similar lines in 2 files"
self._test_output(