Skip to content

Commit

Permalink
Merge pull request #552 from edreamleo/ekr-flake8
Browse files Browse the repository at this point in the history
PR for #551: fix minor flake8 complaints
  • Loading branch information
lieryan committed Dec 3, 2022
2 parents 4ae5d41 + ddbb957 commit 7451194
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 32 deletions.
211 changes: 211 additions & 0 deletions .pylintrc
@@ -0,0 +1,211 @@
# A settings file for running pylint on Rope.

# Run pylint from the top-level Rope directory: `python -m pylint rope`

# This file tested on pylint 2.14.4, Python 3.10.5, as reported by `python -m pylint --version`.

[MASTER]

# Add <file or directory> to the black list. A base name, not a path.
ignore=
.git

# Files or directories matching regex, in Windows or Posix format.
ignore-paths=

# Pickle collected data for later comparisons.
persistent=yes

[MESSAGES CONTROL]

# Enable the message, report, category or checker with the given id(s).
# enable=

# Disable the message, report, category or checker with the given id(s).
disable=

# Catagories to disable: expensive or make-work
# typecheck

basic, # Check on names. Unimportant.
classes, # Unimportant.
design, # Make work.
format, # Use black
imports, # Creates import graph. Expensive?
similarities, # Expensive.
typecheck, # Unimportant
variables, # Unimportant.

# Black. Suppress checks that conflict with Black's conventions.

line-too-long,

# Rope: Suppress checks that conflict with Rope's conventions.

bad-classmethod-argument,
eval-used,
function-redefined,
inconsistent-return-statements,
invalid-name,
no-else-return,
no-self-argument,
signature-differs, # Maybe.
not-callable, # Maybe.
unexpected-special-method-signature,

# Rope: potentially serious warnings.

arguments-differ,
dangerous-default-value,
modified-iterating-list,
used-before-assignment,
unsubscriptable-object,
unpacking-non-sequence,

# Rope: to be removed.

duplicate-string-formatting-argument,
no-else-raise, # Unnecessary "else" after "raise", remove the "else" and de-indent the code inside it.
reimported,
superfluous-parens,
unused-import,
unused-wildcard-import,
useless-super-delegation,

useless-else-on-loop, #Else clause on loop without a break statement, remove the else and de-indent all the code inside it.
unidiomatic-typecheck,
wildcard-import,
wrong-import-order,

# Rope: Additional (temporary?) suppressions.

abstract-method,
arguments-differ,
consider-merging-isinstance,
consider-using-enumerate,
deprecated-method,
implicit-str-concat,
logging-fstring-interpolation,
no-member,
no-staticmethod-decorator, # Consider using a decorator instead of calling staticmethod.
non-parent-init-called,
raise-missing-from,
super-init-not-called,
unnecessary-lambda,
unsupported-assignment-operation,

# Leo: Standard suppressions.

arguments-renamed, # cursesGui2.py
assignment-from-no-return, # Causes problems when base class return None.
assignment-from-none, # Causes problems when base class return None.
attribute-defined-outside-init,
broad-except, # except Exception is justified if followed by g.es_exception.
c-extension-no-member, # Too many errors re pyQt6.
condition-evals-to-constant,
consider-iterating-dictionary,
consider-using-from-import,
consider-using-f-string, # complains about regex's!
consider-using-in,
consider-using-dict-comprehension,
consider-using-dict-items,
consider-using-generator,
consider-using-max-builtin,
consider-using-set-comprehension,
consider-using-ternary,
consider-using-with,
cyclic-import,
deprecated-module,
exec-used,
f-string-without-interpolation, # Useful for concatenated f-strings.
global-statement, # Assume we know what we are doing.
global-variable-not-assigned, # not helpful.
import-error, # Ignore imports of optional packages.
import-outside-toplevel, # Requires substantial code changes.
keyword-arg-before-vararg, # See https://github.com/PyCQA/pylint/issues/2027
missing-docstring, # Instead, use Leo's find-missing-docstrings command.
no-else-break, # **Possible pylint bug**
protected-access,
redeclared-assigned-name,
redefined-argument-from-local, # I do this all the time.
redefined-builtin, # all, next, etc. so what?
redefined-outer-name,
too-few-public-methods,
trailing-whitespace, # Too picky. No need to constantly do clean-all-lines.
unnecessary-comprehension,
unnecessary-dunder-call, # pylint for python 3.10 only.
unnecessary-lambda-assignment,
unnecessary-pass, # Can be pedantic in some situations.
unspecified-encoding, # Huh?
unused-argument,
unused-private-member, # too many false positives.
unused-variable, # way too many false positives, esp. tuple unpacking.
use-dict-literal,
use-list-literal,
use-maxsplit-arg, # What is this??
using-constant-test,

# Good warnings. Don't suppress these.

# bad-option-value, # obsolete pylint option.
# unrecognized-option, # newer python.

# bad-builtin,
# bad-continuation,
# bad-option-value, # obsolete pylint option.
# chained-comparison,
# len-as-condition,
# import-error, # Warns when an import fails: useful now that we are only using python 3.
# literal-comparison,
# locally-disabled,
# multiple-statements,
# no-else-raise,
# no-init,
# no-value-for-parameter,
# not-an-iterable,
# old-style-class, # Probably not an issue.
# simplifiable-if-statement,
# singleton-comparison,
# superfluous-parens,
# trailing-comma-tuple,
# unsupported-assignment-operation,
# unsupported-delete-operation,
# unsubscriptable-object,
# useless-object-inheritance, # class x(object):
# useless-return,

[REPORTS]

# Set the output format. Multiple values are allowed.
output-format=text # colorized, text, parseable, msvs (visual studio)

reports=no # Display only messages.

score=no # Deactivate the evaluation score.

[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
# notes=FIXME,XXX,TODO
notes=

# The following sections are all suppressed above.

[BASIC]

[CLASSES]

[DESIGN]

# Maximum number of nested blocks for function / method body
max-nested-blocks=10 # Apparently, this can't be suppressed!

[FORMAT]

[IMPORTS]

[SIMILARITIES]

[TYPECHECK]

[VARIABLES]
2 changes: 1 addition & 1 deletion rope/base/fscommands.py
Expand Up @@ -103,7 +103,7 @@ def __init__(self, root):
traceback=False,
report_untrusted=False,
)
except:
except Exception:
self.ui = self.hg.ui.ui()
self.ui.setconfig("ui", "interactive", "no")
self.ui.setconfig("ui", "debug", "no")
Expand Down
2 changes: 1 addition & 1 deletion rope/base/oi/doa.py
Expand Up @@ -188,7 +188,7 @@ def receive_data(self):
buf_digest = base64.b64decode(buf[:digest_end])
buf_data = buf[digest_end + 1 : -1]
decoded_buf_data = base64.b64decode(buf_data)
except:
except Exception:
# Corrupted data; the payload cannot be trusted and just has
# to be dropped. See CVE-2014-3539.
continue
Expand Down
2 changes: 1 addition & 1 deletion rope/base/project.py
Expand Up @@ -273,7 +273,7 @@ def _init_prefs(self, prefs):

def _init_other_parts(self):
# Forcing the creation of `self.pycore` to register observers
self.pycore
self.pycore # pylint: disable=pointless-statement

def is_ignored(self, resource):
return self.ignored.does_match(resource)
Expand Down
1 change: 0 additions & 1 deletion rope/base/pycore.py
@@ -1,6 +1,5 @@
import bisect
import difflib
import sys
import warnings

import rope.base.libutils
Expand Down
4 changes: 2 additions & 2 deletions rope/base/pyobjectsdef.py
Expand Up @@ -106,7 +106,7 @@ def get_kind(self):
@property
def decorators(self):
try:
return getattr(self.ast_node, "decorator_list")
return self.ast_node.decorator_list
except AttributeError:
return getattr(self.ast_node, "decorators", None)

Expand Down Expand Up @@ -455,7 +455,7 @@ def _AugAssign(self, node):
pass

def _For(self, node):
self._update_evaluated(node.target, node.iter, ".__iter__().next()") # noqa
self._update_evaluated(node.target, node.iter, ".__iter__().next()")
for child in node.body + node.orelse:
ast.walk(child, self)

Expand Down
8 changes: 4 additions & 4 deletions rope/base/pyscopes.py
Expand Up @@ -328,14 +328,14 @@ def find_scope_end(self, scope):
body_indents = self._get_scope_indents(scope) + 4
else:
body_indents = self._get_body_indents(scope)
for l in self.logical_lines.generate_starts(
for line_start in self.logical_lines.generate_starts(
min(end + 1, self.lines.length()), self.lines.length() + 1
):
if not self._is_empty_line(l):
if self.get_indents(l) < body_indents:
if not self._is_empty_line(line_start):
if self.get_indents(line_start) < body_indents:
return end
else:
end = l
end = line_start
return end

@property
Expand Down
2 changes: 1 addition & 1 deletion rope/refactor/extract.py
Expand Up @@ -902,7 +902,7 @@ def _flatten_nested_tuple_of_names(self, node):
elif isinstance(node, ast.Name):
yield node.id
else:
assert False, "Unexpected node type in list comprehension target: %s" % node
assert False, f"Unexpected node type in list comprehension target: {node!r}"

def _If(self, node):
self._handle_conditional_node(node)
Expand Down
2 changes: 1 addition & 1 deletion rope/refactor/importutils/module_imports.py
Expand Up @@ -574,7 +574,7 @@ def _get_names(self, alias_names):

def find_import_statements(self):
nodes = self.pymodule.get_ast().body
for index, node in enumerate(nodes):
for node in nodes:
if isinstance(node, (ast.Import, ast.ImportFrom)):
lines = self.pymodule.logical_lines
end_line = lines.logical_line_in(node.lineno)[1] + 1
Expand Down
6 changes: 3 additions & 3 deletions rope/refactor/move.py
Expand Up @@ -706,9 +706,9 @@ def rename_in_module(self, new_name, pymodule=None, imports=False, resource=None

def occurs_in_module(self, pymodule=None, resource=None, imports=True):
finder = self._create_finder(imports)
for occurrence in finder.find_occurrences(pymodule=pymodule, resource=resource):
return True
return False
occurrences = finder.find_occurrences(pymodule=pymodule, resource=resource)
sentinel = object()
return next(occurrences, sentinel) is not sentinel

def _create_finder(self, imports):
return occurrences.create_finder(
Expand Down
4 changes: 2 additions & 2 deletions rope/refactor/patchedast.py
Expand Up @@ -536,7 +536,7 @@ def _alias(self, node):
def _handle_function_def_node(self, node, is_async):
children = []
try:
decorators = getattr(node, "decorator_list")
decorators = node.decorator_list
except AttributeError:
decorators = getattr(node, "decorators", None)
if decorators:
Expand Down Expand Up @@ -922,7 +922,7 @@ def consume(self, token, skip_comment=True):
break
else:
self._skip_comment()
except (ValueError, TypeError) as e:
except (ValueError, TypeError) as e: # noqa
raise MismatchedTokenError(
f"Token <{token}> at {self._get_location()} cannot be matched"
)
Expand Down
10 changes: 5 additions & 5 deletions rope/refactor/sourceutils.py
Expand Up @@ -20,15 +20,15 @@ def indent_lines(source_code, amount):
return source_code
lines = source_code.splitlines(True)
result = []
for l in lines:
if l.strip() == "":
for line in lines:
if line.strip() == "":
result.append("\n")
continue
if amount < 0:
indents = codeanalyze.count_line_indents(l)
result.append(max(0, indents + amount) * " " + l.lstrip())
indents = codeanalyze.count_line_indents(line)
result.append(max(0, indents + amount) * " " + line.lstrip())
else:
result.append(" " * amount + l)
result.append(" " * amount + line)
return "".join(result)


Expand Down
2 changes: 1 addition & 1 deletion ropetest/advanced_oi_test.py
Expand Up @@ -1051,7 +1051,7 @@ def test_validation_problems_for_changing_builtin_types(self):
l = {}
v = l["key"]
"""))
pymod1 = self.project.get_pymodule(mod1) # noqa
pymod1 = self.project.get_pymodule(mod1)
var = pymod1["v"].get_object() # noqa

def test_always_returning_containing_class_for_selfs(self):
Expand Down
6 changes: 1 addition & 5 deletions ropetest/contrib/autoimport/utilstest.py
@@ -1,9 +1,5 @@
"""Tests for autoimport utility functions, written in pytest"""

from sys import platform

import pytest

from rope.contrib.autoimport import utils
from rope.contrib.autoimport.defs import Package, PackageType, Source

Expand Down Expand Up @@ -59,5 +55,5 @@ def test_get_package_tuple_typing(typing_path):
def test_get_package_tuple_compiled(compiled_lib):
lib_name, lib_path = compiled_lib
assert Package(
lib_name, Source.STANDARD, lib_path, PackageType.COMPILED
lib_name, Source.STANDARD, lib_path, PackageType.COMPILED
) == utils.get_package_tuple(lib_path)
1 change: 0 additions & 1 deletion ropetest/refactor/patchedasttest.py
Expand Up @@ -1584,7 +1584,6 @@ def test_match_node_with_match_class_match_as_capture_pattern_with_explicit_name
")",
])


@testutils.only_for_versions_higher("3.10")
def test_match_node_with_match_mapping_match_as(self):
source = dedent("""\
Expand Down

0 comments on commit 7451194

Please sign in to comment.