Skip to content

Commit

Permalink
Fixed Pylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Jul 24, 2020
1 parent 164e37c commit 7c910b4
Show file tree
Hide file tree
Showing 43 changed files with 231 additions and 175 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
.DS_Store
__pycache__
dist
venv
packaging/linux/build
build
resources_build
Expand Down Expand Up @@ -47,4 +48,4 @@ packaging/mac/freezing.log
thonny.egg-info
temp_build_dir
thonnyapp/thonnyapp.egg-info
thonnycontrib
thonnycontrib
14 changes: 13 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ disable=locally-disabled,
trailing-newlines,
ungrouped-imports,
wrong-import-order,
check-imports-order,
unused-argument,
no-self-use,
no-else-return,
no-else-break,
no-else-continue,
no-else-raise,
len-as-condition,
bad-continuation,
missing-docstring,
Expand Down Expand Up @@ -98,6 +102,14 @@ disable=locally-disabled,
simplifiable-if-statement,
cyclic-import, # gives many false alarms
unused-import, # typing imports seem to cause this
import-outside-toplevel, # it's OK
import-error, # some imports are done in a conditional path
unnecessary-pass,
subprocess-run-check,
assignment-from-none, # mypy is more precise about this
redefined-outer-name, # many false positives, trips on valid uses, mypy would be more precise





Expand Down Expand Up @@ -201,7 +213,7 @@ dummy-variables-rgx=^_|^dummy

# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
additional-builtins=_

# List of strings which can identify a callback function by name. A callback
# name must start or end with one of those strings.
Expand Down
5 changes: 3 additions & 2 deletions thonny/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def get_ipc_file_path():
for name in ("LOGNAME", "USER", "LNAME", "USERNAME"):
if name in os.environ:
username = os.environ.get(name)
break
else:
username = os.path.basename(os.path.expanduser("~"))

Expand Down Expand Up @@ -157,7 +158,7 @@ def launch():
_prepare_thonny_user_dir()

if not _check_welcome():
return
return 0

if _should_delegate():
try:
Expand Down Expand Up @@ -231,7 +232,7 @@ def copy_contents(src_dir, dest_dir):
def _should_delegate():
if not os.path.exists(get_ipc_file_path()):
# no previous instance
return
return False

from thonny.config import try_load_configuration

Expand Down
6 changes: 4 additions & 2 deletions thonny/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def extract_text_range(source, text_range):
return "".join(lines)


def find_expression(node, text_range):
for node in ast.walk(node):
def find_expression(start_node, text_range):
for node in ast.walk(start_node):
if (
isinstance(node, ast.expr)
and node.lineno == text_range.lineno
Expand All @@ -30,6 +30,8 @@ def find_expression(node, text_range):
):
return node

return None


def parse_source(source: bytes, filename="<unknown>", mode="exec", fallback_to_one_char=False):
root = ast.parse(source, filename, mode)
Expand Down
9 changes: 5 additions & 4 deletions thonny/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
from collections import namedtuple
from importlib.machinery import PathFinder, SourceFileLoader

import __main__ # @UnresolvedImport
import _ast

import __main__ # @UnresolvedImport
import thonny
from thonny.common import path_startswith # TODO: try to get rid of this
from thonny.common import (
Expand Down Expand Up @@ -373,7 +374,7 @@ def signal_handler(signal_, frame):
raise KeyboardInterrupt("Execution interrupted")

if os.name == "nt":
signal.signal(signal.SIGBREAK, signal_handler) # @UndefinedVariable
signal.signal(signal.SIGBREAK, signal_handler) # pylint: disable=no-member
else:
signal.signal(signal.SIGINT, signal_handler)

Expand Down Expand Up @@ -547,8 +548,8 @@ def _cmd_get_active_distributions(self, cmd):
"location": dist.location,
"version": dist.version,
}
for dist in pkg_resources.working_set
} # pylint: disable=not-an-iterable
for dist in pkg_resources.working_set # pylint: disable=not-an-iterable
}

return InlineResponse(
"get_active_distributions",
Expand Down
2 changes: 1 addition & 1 deletion thonny/backend_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
+ "Choose another interpreter from Tools => Options => Interpreter",
file=sys.stderr,
)
exit()
sys.exit()

import logging
import os.path
Expand Down
18 changes: 8 additions & 10 deletions thonny/base_file_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,16 +667,19 @@ def create_new_file(self):
name = askstring("File name", "Provide filename", initialvalue="")

if not name:
return
return None

path = self.join(parent_path, name)

if name in self._cached_child_data[parent_path]:
# TODO: ignore case in windows
messagebox.showerror("Error", "The file '" + path + "' already exists")
return self.create_new_file()
else:
self.open_file(path)

return path

def delete(self):
selection = self.get_selection_info(True)
if not selection:
Expand Down Expand Up @@ -811,13 +814,6 @@ def request_fs_info(self, path):
def perform_delete(self, paths, description):
# Deprecated. moving to trash should be used instead
raise NotImplementedError()
"""
for path in sorted(paths, key=len, reverse=True):
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
"""

def perform_move_to_trash(self, paths, description):
# TODO: do it with subprocess dialog
Expand Down Expand Up @@ -949,6 +945,8 @@ def request_focus_into(self, path):
else:
self.request_new_focus(path)

return True

def request_new_focus(self, path):
# Overridden in active browser
self.focus_into(path)
Expand Down Expand Up @@ -1143,9 +1141,9 @@ def on_remote(self, event=None):

def on_return(self, event=None):
if self.focus_get() == self.local_button:
return self.on_local(event)
self.on_local(event)
elif self.focus_get() == self.remote_button:
return self.on_remote(event)
self.on_remote(event)

def on_down(self, event=None):
if self.focus_get() == self.local_button:
Expand Down
4 changes: 1 addition & 3 deletions thonny/codeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ def __init__(self, master, propose_remove_line_numbers=False, **text_frame_args)

assert self._first_line_number is not None

self._syntax_theme_change_binding = get_workbench().bind(
"SyntaxThemeChanged", self._reload_theme_options, True
)
get_workbench().bind("SyntaxThemeChanged", self._reload_theme_options, True)
self._original_newlines = os.linesep
self._reload_theme_options()
self._gutter.bind("<Double-Button-1>", self._toggle_breakpoint, True)
Expand Down
2 changes: 1 addition & 1 deletion thonny/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def get_windows_network_locations():
"size": None,
"time": None,
}
except:
except Exception:
logging.getLogger("thonny").error(
"Can't get target from %s", lnk_path, exc_info=True
)
Expand Down
12 changes: 7 additions & 5 deletions thonny/config_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class ConfigurationDialog(CommonDialog):
last_shown_tab_index = 0

def __init__(self, master, page_records):
def __init__(self, master, page_records_with_order):
super().__init__(master)
width = ems_to_pixels(53)
height = ems_to_pixels(43)
Expand All @@ -33,7 +33,9 @@ def __init__(self, master, page_records):
self._cancel_button.grid(row=1, column=2, padx=(0, 11), pady=(0, 10))

self._page_records = []
for key, title, page_class, order in sorted(page_records, key=lambda r: (r[3], r[0])):
for key, title, page_class, _ in sorted(
page_records_with_order, key=lambda r: (r[3], r[0])
):
try:
spacer = ttk.Frame(self)
spacer.rowconfigure(0, weight=1)
Expand All @@ -57,17 +59,17 @@ def select_page(self, key):
self._notebook.select(tab)

def _ok(self, event=None):
for key, title, page in self._page_records:
for _, title, page in self._page_records:
try:
if page.apply() == False:
if not page.apply():
return
except Exception:
get_workbench().report_exception("Error when applying options in " + title)

self.destroy()

def _cancel(self, event=None):
for key, title, page in self._page_records:
for _, title, page in self._page_records:
try:
page.cancel()
except Exception:
Expand Down
12 changes: 6 additions & 6 deletions thonny/code.py → thonny/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import sys
import tkinter as tk
import traceback
from _tkinter import TclError
from logging import exception
from tkinter import messagebox, ttk

from _tkinter import TclError

from thonny import get_runner, get_workbench, ui_utils
from thonny.base_file_browser import ask_backend_path, choose_node_for_file_operations
from thonny.codeview import CodeView
Expand Down Expand Up @@ -164,7 +165,6 @@ def _load_file(self, filename, keep_undo=False):
"This file seems to have problems with encoding.\n\n"
+ "Make sure it is in UTF-8 or contains proper encoding hint.",
)
return False

self.update_appearance()

Expand Down Expand Up @@ -692,7 +692,7 @@ def _cmd_new_file(self):
def _cmd_open_file(self):
node = choose_node_for_file_operations(self.winfo_toplevel(), "Where to open from?")
if not node:
return None
return

if node == "local":
initialdir = get_workbench().get_local_cwd()
Expand All @@ -706,7 +706,7 @@ def _cmd_open_file(self):
assert node == "remote"
target_path = ask_backend_path(self.winfo_toplevel(), "open")
if not target_path:
return None
return

path = make_remote_path(target_path)

Expand Down Expand Up @@ -979,11 +979,11 @@ def get_current_breakpoints():
def get_saved_current_script_filename(force=True):
editor = get_workbench().get_editor_notebook().get_current_editor()
if not editor:
return
return None

filename = editor.get_filename(force)
if not filename:
return
return None

if editor.is_modified():
filename = editor.save_file()
Expand Down
2 changes: 2 additions & 0 deletions thonny/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ def get_language_code_by_name(name):
for code in LANGUAGES_DICT:
if LANGUAGES_DICT[code] == name:
return code

raise RuntimeError("Unknown language name '%s'" % name)
10 changes: 5 additions & 5 deletions thonny/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def parse_cmd_line(s):
def levenshtein_distance(s1, s2):
# https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Python
if len(s1) < len(s2):
return levenshtein_distance(s2, s1)
return levenshtein_distance(s2, s1) # pylint: disable=arguments-out-of-order

# len(s1) >= len(s2)
if len(s2) == 0:
Expand Down Expand Up @@ -286,15 +286,15 @@ def levenshtein_damerau_distance(s1, s2, maxDistance):
# match a, change e->i change i->e => aie
# Damarau-Levenshtein has a cost of 1
# match a, transpose ei to ie => aie
transpositionRow = None
prevRow = None
transpositionRow = []
prevRow = []

# build first leven matrix row
# The first row represents transformation from an empty string
# to the shorter string making it static [0-n]
# since this row is static we can set it as
# curRow and start computation at the second row or index 1
curRow = [x for x in range(0, l1 + 1)]
curRow = list(range(0, l1 + 1))

# use second length to loop through all the rows being built
# we start at row one
Expand Down Expand Up @@ -384,7 +384,7 @@ def time_left(self):

def copy_to_clipboard(data):
if running_on_windows():
return _copy_to_windows_clipboard(data)
_copy_to_windows_clipboard(data)
elif running_on_mac_os():
command = ["pbcopy"]
else:
Expand Down
4 changes: 2 additions & 2 deletions thonny/plugins/ast_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _update(self, event):
def _format(key, node, parent_id):

if isinstance(node, ast.AST):
fields = [(key, val) for key, val in ast.iter_fields(node)]
fields = list(ast.iter_fields(node))

value_label = node.__class__.__name__

Expand Down Expand Up @@ -164,7 +164,7 @@ def _find_closest_containing_node(tree, text_range):
def pretty(node, key="/", level=0):
"""Used for exporting ASTView content"""
if isinstance(node, ast.AST):
fields = [(key, val) for key, val in ast.iter_fields(node)]
fields = list(ast.iter_fields(node))
value_label = node.__class__.__name__
if isinstance(node, ast.Call):
# Try to make 3.4 AST-s more similar to 3.5
Expand Down
1 change: 0 additions & 1 deletion thonny/plugins/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from thonny.common import InlineCommand
from thonny.shell import ShellText


# TODO: adjust the window position in cases where it's too close to bottom or right edge - but make sure the current line is shown
"""Completions get computed on the backend, therefore getting the completions is
asynchronous.
Expand Down
3 changes: 3 additions & 0 deletions thonny/plugins/backend_config_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class BackendDetailsConfigPage(ConfigurationPage):
def should_restart(self):
raise NotImplementedError()

def _on_change(self):
pass

def _add_text_field(self, label_text, variable_name, row, show=None):
entry_label = ttk.Label(self, text=label_text)
entry_label.grid(row=row, column=0, sticky="w")
Expand Down
2 changes: 1 addition & 1 deletion thonny/plugins/birdseye_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def close_server():
if _server_process is not None:
try:
_server_process.kill()
except:
except Exception:
pass


Expand Down
Loading

0 comments on commit 7c910b4

Please sign in to comment.