Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pyflakes and flake8 complaints #540

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c6bb22b
Remove more pyflakes complaints
edreamleo Nov 27, 2022
88845e7
Clean three more test files
edreamleo Nov 27, 2022
6320cce
Clean type_hinting_test.py
edreamleo Nov 27, 2022
7fd89d6
Clean pyscopestest.py
edreamleo Nov 27, 2022
48a7987
Clean pycoretest.py
edreamleo Nov 27, 2022
4e18b19
Clean projecttest.py
edreamleo Nov 27, 2022
98519e3
Clean three more test files
edreamleo Nov 27, 2022
d120985
Three more files
edreamleo Nov 27, 2022
f272d1c
Clean yet another three files
edreamleo Nov 27, 2022
e907fcd
Yes, the two imports in rope/refactor/__init__.py are essential
edreamleo Nov 27, 2022
078079f
Clean three type_hinting files
edreamleo Nov 27, 2022
6fea91e
Simplify use of '_follow', removing pyflakes complaint
edreamleo Nov 27, 2022
7ac86b9
Add assert, working around an apparent pyflakes bug
edreamleo Nov 27, 2022
e759e1e
Remove another unused import of pycompat
edreamleo Nov 27, 2022
ad6867f
Clean more files
edreamleo Nov 27, 2022
02289a3
Explain an assert
edreamleo Nov 27, 2022
a09ff5f
Fix valid flake8 complaints
edreamleo Nov 27, 2022
9ef282c
Fix several flake8 complaints in testutils.py
edreamleo Nov 27, 2022
f955790
Add trailing newline
edreamleo Nov 27, 2022
f3aa011
Add '# noqa' to two files
edreamleo Nov 27, 2022
6988104
Merge branch 'master' into ekr-clean-pyflakes
edreamleo Nov 27, 2022
b376561
Merge branch 'master' into ekr-clean-pyflakes
edreamleo Nov 27, 2022
dc6e00c
Merge branch 'ekr-clean-pyflakes' of https://github.com/edreamleo/ekr…
edreamleo Nov 27, 2022
529ad9e
Blacken four files
edreamleo Nov 27, 2022
4f4b128
Remove an pyflakes-related assert
edreamleo Nov 27, 2022
bdb0ce2
Blacken
edreamleo Nov 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rope/base/ast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ast
from ast import *
import ast # noqu
from ast import * # noqa

from rope.base import fscommands

Expand Down
2 changes: 0 additions & 2 deletions rope/base/fscommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import os
import shutil
import subprocess

import rope.base.utils.pycompat as pycompat
import typing


Expand Down
4 changes: 1 addition & 3 deletions rope/base/oi/soa.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def _follow(pyfunction):
pycore, pyfunction, return_true, return_false, new_followed_calls
)

if not followed_calls:
_follow = None
visitor = SOAVisitor(pycore, pydefined, _follow)
visitor = SOAVisitor(pycore, pydefined, _follow if followed_calls else None)
for child in rope.base.ast.get_child_nodes(pydefined.get_ast()):
rope.base.ast.walk(child, visitor)

Expand Down
13 changes: 6 additions & 7 deletions rope/base/oi/type_hinting/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Based on super lightweight Simple Top-Down Parser from http://effbot.org/zone/simple-top-down-parsing.htm
# and https://bitbucket.org/emacsway/sqlbuilder/src/default/sqlbuilder/smartsql/contrib/evaluate.py
import re
from rope.base.utils import pycompat
from rope.base.oi.type_hinting import utils
from rope.base import utils as base_utils

Expand Down Expand Up @@ -268,15 +267,15 @@ def led(self, left, parser):


@method(symbol("["))
def evaluate(self, pyobject):
def evaluate(self, pyobject): # noqa
return utils.parametrize_type(
self.first.evaluate(pyobject), *[i.evaluate(pyobject) for i in self.second]
)


# Anonymous Function Calls
@method(symbol("("))
def nud(self, parser):
def nud(self, parser): # noqa
self.second = []
if parser.token.name != ")":
while 1:
Expand All @@ -292,7 +291,7 @@ def nud(self, parser):

# Function Calls
@method(symbol("("))
def led(self, left, parser):
def led(self, left, parser): # noqa
self.first = left
self.second = []
if parser.token.name != ")":
Expand All @@ -308,14 +307,14 @@ def led(self, left, parser):


@method(symbol("("))
def evaluate(self, pyobject):
def evaluate(self, pyobject): # noqa
# TODO: Implement me
raise NotImplementedError


@method(symbol("or"))
@method(symbol("|"))
def evaluate(self, pyobject):
def evaluate(self, pyobject): # noqa
# TODO: Implement me
raise NotImplementedError

Expand Down Expand Up @@ -355,4 +354,4 @@ def __call__(self, program, pyobject):
return ast.evaluate(pyobject)


evaluate = Evaluator()
evaluate = Evaluator() # noqa
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from rope.base.oi.type_hinting import utils

from rope.base.oi.type_hinting.providers import interfaces


Expand Down
6 changes: 1 addition & 5 deletions rope/base/oi/type_hinting/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import logging
from typing import Optional, Union

try:
from typing import Union, Optional
except ImportError:
pass
import rope.base.utils as base_utils
from rope.base import evaluate
from rope.base.exceptions import AttributeNotFoundError
from rope.base.pyobjects import PyClass, PyDefinedObject, PyFunction, PyObject
from rope.base.utils import pycompat


def get_super_func(pyfunc):
Expand Down
2 changes: 0 additions & 2 deletions rope/base/pycore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import bisect
import difflib
import sys
import warnings

import rope.base.libutils
Expand All @@ -15,7 +14,6 @@
from rope.base import stdmods
from rope.base import taskhandle
from rope.base import utils
from rope.base.exceptions import ModuleNotFoundError


class PyCore:
Expand Down
5 changes: 1 addition & 4 deletions rope/base/pyobjectsdef.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from rope.base.pynames import DefinedName
import rope.base.builtins
import rope.base.codeanalyze
import rope.base.evaluate
Expand Down Expand Up @@ -461,9 +460,7 @@ def _AugAssign(self, node):
pass

def _For(self, node):
names = 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
1 change: 1 addition & 0 deletions rope/contrib/autoimport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .pickle import AutoImport as _PickleAutoImport
from .sqlite import AutoImport as _SqliteAutoImport

assert _SqliteAutoImport # Workaround for an apparent pyflakes bug.

AutoImport = _PickleAutoImport

Expand Down
7 changes: 5 additions & 2 deletions rope/refactor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
monitoring the progress of refactorings.

"""
from rope.refactor.importutils import ImportOrganizer # noqa
from rope.refactor.topackage import ModuleToPackage # noqa
from rope.refactor.importutils import ImportOrganizer # essential.
from rope.refactor.topackage import ModuleToPackage # essential.

assert ImportOrganizer
assert ModuleToPackage


__all__ = [
Expand Down
1 change: 0 additions & 1 deletion rope/refactor/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import rope.base.exceptions
import rope.refactor.functionutils
from rope.base import (
ast,
pynames,
pyobjects,
codeanalyze,
Expand Down
2 changes: 1 addition & 1 deletion rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def consume(self, token, skip_comment=True):
break
else:
self._skip_comment()
except (ValueError, TypeError) as e:
except (ValueError, TypeError):
raise MismatchedTokenError(
"Token <{}> at {} cannot be matched".format(token, self._get_location())
)
Expand Down
1 change: 0 additions & 1 deletion rope/refactor/suites.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from itertools import chain

from rope.base import ast
from rope.base.utils import pycompat


def find_visible(node, lines):
Expand Down
13 changes: 6 additions & 7 deletions ropetest/advanced_oi_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from textwrap import dedent

from rope.base.builtins import Str

import unittest

from rope.base.builtins import Str
import rope.base.libutils
import rope.base.oi
from rope.base.utils import pycompat
from ropetest import testutils


Expand Down Expand Up @@ -1052,9 +1049,10 @@ def test_validation_problems_for_changing_builtin_types(self):
l = {}
v = l["key"]
"""))
pymod1 = self.project.get_pymodule(mod1) # noqa
var = pymod1["v"].get_object() # noqa

pymod1 = self.project.get_pymodule(mod1)
var = pymod1["v"].get_object()
self.assertTrue(pymod1 is not None)
self.assertTrue(var is not None)
def test_always_returning_containing_class_for_selfs(self):
code = dedent("""\
class A(object):
Expand Down Expand Up @@ -1100,3 +1098,4 @@ def test_set_comprehension(self):
self.mod.write(code)
pymod = self.project.get_pymodule(self.mod)
x_var = pymod["x"].pyobject.get()
self.assertTrue(x_var is not None)
3 changes: 2 additions & 1 deletion ropetest/builtinstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,9 @@ class C1(object):
pymod = self.project.get_pymodule(self.mod)
c1_class = pymod["C1"].get_object()
a_var = pymod["a"].get_object()
b_var = pymod["b"].get_object() # noqa
b_var = pymod["b"].get_object()
self.assertEqual(c1_class, a_var.get_type())
self.assertTrue(b_var is not None)

def test_enumerate_builtin_function(self):
self.mod.write(dedent("""\
Expand Down
6 changes: 4 additions & 2 deletions ropetest/codeanalyzetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def test_getting_primary_before_get_index(self):

def test_getting_primary_and_strings_at_the_end_of_line(self):
code = "f('\\'')\n"
result = self._find_primary(code, len(code) - 1) # noqa
result = self._find_primary(code, len(code) - 1)
self.assertTrue(result is not None)

def test_getting_primary_and_not_crossing_newlines(self):
code = "\na = (b + c)\n(4 + 1).x\n"
Expand Down Expand Up @@ -753,14 +754,15 @@ def test_relative_modules_after_from_statements2(self):
mod1 = testutils.create_module(self.project, "mod1")
pkg1 = testutils.create_package(self.project, "pkg1")
pkg2 = testutils.create_package(self.project, "pkg2", pkg1)
mod2 = testutils.create_module(self.project, "mod2", pkg2) # noqa
mod2 = testutils.create_module(self.project, "mod2", pkg2)
mod1.write("import pkg1.pkg2.mod2")

mod1_scope = self.project.get_pymodule(mod1).get_scope()
name_finder = rope.base.evaluate.ScopeNameFinder(mod1_scope.pyobject)
pkg2_pyobject = self.project.get_pymodule(pkg2)
found_pyname = name_finder.get_pyname_at(mod1.read().index("pkg2") + 1)
self.assertEqual(pkg2_pyobject, found_pyname.get_object())
self.assertTrue(mod2 is not None)

def test_get_pyname_at_on_language_keywords(self):
code = dedent("""\
Expand Down
6 changes: 1 addition & 5 deletions ropetest/contrib/autoimport/utilstest.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 10 additions & 5 deletions ropetest/contrib/codeassisttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,8 @@ def my_global_func():
pass
my_""")
result = self._assist(code)
proposals = sorted_proposals(result, typepref=["function"]) # noqa
proposals = sorted_proposals(result, typepref=["function"])
self.assertTrue(proposals is not None)

def test_get_pydoc_unicode(self):
src = dedent('''\
Expand Down Expand Up @@ -824,7 +825,8 @@ def test_commenting_errors_before_offset(self):
s = "hey"
s.replace()
""")
doc = get_doc(self.project, src, src.rindex("replace") + 1) # noqa
doc = get_doc(self.project, src, src.rindex("replace") + 1)
self.assertTrue(doc is not None)

def test_proposing_variables_defined_till_the_end_of_scope(self):
code = dedent("""\
Expand Down Expand Up @@ -928,7 +930,8 @@ def test_and_normal_complete_blocks_and_single_fixing(self):
except:
pass
""")
result = self._assist(code, code.index("."), maxfixes=1) # noqa
result = self._assist(code, code.index("."), maxfixes=1)
self.assertTrue(result is not None)

def test_nested_blocks(self):
code = dedent("""\
Expand All @@ -951,7 +954,8 @@ def test_proposing_function_keywords_when_calling_for_non_functions(self):
code = dedent("""\
f = 1
f(p""")
result = self._assist(code) # noqa
result = self._assist(code)
self.assertTrue(result is not None)

def test_proposing_function_keywords_when_calling_extra_spaces(self):
code = dedent("""\
Expand Down Expand Up @@ -1337,7 +1341,8 @@ def _underlined_func():
""")
samplemod.write(code)
package = testutils.create_package(self.project, "package")
nestedmod = testutils.create_module(self.project, "nestedmod", package) # noqa
nestedmod = testutils.create_module(self.project, "nestedmod", package)
self.assertTrue(nestedmod is not None)

def tearDown(self):
testutils.remove_project(self.project)
Expand Down
3 changes: 2 additions & 1 deletion ropetest/contrib/fixmodnamestest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def test_fixing_contents(self):

def test_handling_nested_modules(self):
pkg = create_package(self.project, "xkg")
mod = create_module(self.project, "xkg.xod") # noqa
mod = create_module(self.project, "xkg.xod")
self.project.do(FixModuleNames(self.project).get_changes(_fixer))
self.assertFalse(pkg.exists())
self.assertTrue(self.project.get_resource("_kg/__init__.py").exists())
self.assertTrue(self.project.get_resource("_kg/_od.py").exists())
self.assertTrue(mod is not None)


def _fixer(name):
Expand Down
6 changes: 4 additions & 2 deletions ropetest/historytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def test_change_set_saving(self):
self.assertFalse(myfile.exists())

def test_writing_and_reading_history(self):
history_file = self.project.get_file("history.pickle") # noqa
history_file = self.project.get_file("history.pickle")
self.project.set("save_history", True)
history = rope.base.history.History(self.project)
myfile = self.project.get_file("myfile.txt")
Expand All @@ -383,9 +383,10 @@ def test_writing_and_reading_history(self):
history = rope.base.history.History(self.project)
history.undo()
self.assertFalse(myfile.exists())
self.assertTrue(history_file is not None)

def test_writing_and_reading_history2(self):
history_file = self.project.get_file("history.pickle") # noqa
history_file = self.project.get_file("history.pickle")
self.project.set("save_history", True)
history = rope.base.history.History(self.project)
myfile = self.project.get_file("myfile.txt")
Expand All @@ -396,3 +397,4 @@ def test_writing_and_reading_history2(self):
history = rope.base.history.History(self.project)
history.redo()
self.assertTrue(myfile.exists())
self.assertTrue(history_file is not None)
3 changes: 2 additions & 1 deletion ropetest/objectinfertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def test_empty_tuples(self):
""")
mod = libutils.get_string_module(self.project, code)

a = mod["a"].get_object() # noqa
a = mod["a"].get_object()
self.assertTrue(a is not None)

def test_handling_generator_functions(self):
code = dedent("""\
Expand Down
Loading