🐛 Fix issues pointed out by flake-bugbear

This commit is contained in:
Gina Häußge committed 2020-10-08 11:50:24 +02:00
1 parent bc785141e5
commit 446e1b7ece
22 files changed
+38 -36

No files matched your search

+2
View File
@@ -36,6 +36,8 @@ repos:
rev: 3.8.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- repo: https://github.com/prettier/prettier
rev: master
hooks:
+2 -2
View File
@@ -468,7 +468,7 @@ def init_pluginsystem(
def validator(phase, plugin_info):
if phase in ("before_import", "before_load", "before_enable"):
setattr(plugin_info, "safe_mode_victim", not plugin_info.bundled)
plugin_info.safe_mode_victim = not plugin_info.bundled
if not plugin_info.bundled:
return False
return True
@@ -497,7 +497,7 @@ def init_pluginsystem(
plugin.needs_restart = True
# plugin has a settings overlay, inject it
overlay_definition = getattr(plugin.instance, "__plugin_settings_overlay__")
overlay_definition = plugin.instance.__plugin_settings_overlay__
if isinstance(overlay_definition, (tuple, list)):
overlay_definition, order = overlay_definition
else:
+1 -1
View File
@@ -687,7 +687,7 @@ def get_versions():
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split("/"):
for _ in cfg.versionfile_source.split("/"):
root = os.path.dirname(root)
except NameError:
return {
+1 -1
View File
@@ -106,7 +106,7 @@ def client(ctx, apikey, host, port, httpuser, httppass, https, prefix):
)
except FatalStartupError as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
click.echo("There was a fatal error initializing the client.", err=True)
ctx.exit(-1)
+5 -5
View File
@@ -67,7 +67,7 @@ def config(ctx):
get_ctx_obj_option(ctx, "configfile", None),
)
except FatalStartupError as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
click.echo("There was a fatal error initializing the settings manager.", err=True)
ctx.exit(-1)
@@ -87,7 +87,7 @@ def set_command(ctx, path, value, as_bool, as_float, as_int, as_json):
try:
value = json.loads(value)
except Exception as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
ctx.exit(-1)
data_type = None
@@ -124,7 +124,7 @@ def append_value_command(ctx, path, value, as_json=False):
try:
value = json.loads(value)
except Exception as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
ctx.exit(-1)
current = ctx.obj.settings.get(path)
@@ -153,7 +153,7 @@ def insert_value_command(ctx, path, index, value, as_json=False):
try:
value = json.loads(value)
except Exception as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
ctx.exit(-1)
current = ctx.obj.settings.get(path)
@@ -181,7 +181,7 @@ def remove_value_command(ctx, path, value, as_json=False):
try:
value = json.loads(value)
except Exception as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
ctx.exit(-1)
current = ctx.obj.settings.get(path)
+1 -1
View File
@@ -89,7 +89,7 @@ class OctoPrintPluginCommands(click.MultiCommand):
self.settings, safe_mode=get_ctx_obj_option(ctx, "safe_mode", False)
)
except FatalStartupError as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
click.echo(
"There was a fatal error initializing the settings or the plugin system.",
err=True,
+1 -1
View File
@@ -262,7 +262,7 @@ def enable_safemode(ctx, **kwargs):
get_ctx_obj_option(ctx, "configfile", None),
)
except FatalStartupError as e:
click.echo(e.message, err=True)
click.echo(str(e), err=True)
click.echo("There was a fatal error initializing the settings manager.", err=True)
ctx.exit(-1)
else:
+3 -3
View File
@@ -129,7 +129,7 @@ def get_all_extensions(subtree=None):
result = []
if isinstance(subtree, dict):
for key, value in subtree.items():
for value in subtree.values():
if isinstance(value, dict):
result += get_all_extensions(value)
elif isinstance(value, (ContentTypeMapping, ContentTypeDetector)):
@@ -167,7 +167,7 @@ def get_content_type_mapping_for_extension(extension, subtree=None):
if subtree is None:
subtree = full_extension_tree()
for key, value in subtree.items():
for value in subtree.values():
content_extension_matches = (
isinstance(value, (ContentTypeMapping, ContentTypeDetector))
and extension in value.extensions
@@ -313,7 +313,7 @@ class FileManager(object):
if root is not None:
backlog_generator = storage_manager.analysis_backlog_for_path(path=root)
for entry, path, printer_profile in backlog_generator:
for entry, path, _ in backlog_generator:
file_type = get_file_type(path)[-1]
file_name = storage_manager.split_path(path)
+2 -2
View File
@@ -1712,7 +1712,7 @@ class PluginManager(object):
)
self.plugin_implementations[name] = plugin.implementation
setattr(plugin.implementation, "__timing_wrapped", True)
plugin.implementation.__timing_wrapped = True
def _deactivate_plugin(self, name, plugin):
for hook, definition in plugin.hooks.items():
@@ -2354,7 +2354,7 @@ class EntryPointMetadata(pkginfo.Distribution):
for metadata_file in metadata_files:
try:
return self.entry_point.dist.get_metadata(metadata_file)
except (IOError, OSError):
except (IOError, OSError): # noqa: B014
# file not found, metadata file might be missing, ignore
# IOError: file not found in Py2
# OSError (specifically FileNotFoundError): file not found in Py3
+1 -1
View File
@@ -433,7 +433,7 @@ class AppKeysPlugin(
def _all_api_keys(self):
with self._keys_lock:
result = []
for user_id, keys in self._keys.items():
for keys in self._keys.values():
result += keys
return result
+1 -1
View File
@@ -969,7 +969,7 @@ class BackupPlugin(
# add list of installed plugins
plugins = []
plugin_folder = settings.global_get_basefolder("plugins")
for key, plugin in plugin_manager.plugins.items():
for plugin in plugin_manager.plugins.values():
if plugin.bundled or (
isinstance(plugin.origin, FolderOrigin)
and plugin.origin.folder == plugin_folder
@@ -46,8 +46,8 @@ IGNORED_EXCEPTIONS = [
# IOErrors of any kind due to a full file system
(
IOError,
lambda exc, logger, plugin, cb: getattr(exc, "errno")
and exc.errno in (getattr(errno, "ENOSPC"),),
lambda exc, logger, plugin, cb: exc.errorgetattr(exc, "errno") # noqa: B009
and exc.errno in (getattr(errno, "ENOSPC"),), # noqa: B009
),
# RequestExceptions of any kind
requests.exceptions.RequestException,
@@ -1312,7 +1312,7 @@ class PluginManagerPlugin(
existing={}, ignore_uninstalled=False
)
for key, plugin in plugins.items():
for plugin in plugins.values():
if plugin.origin is None or plugin.origin.type != "entry_point":
continue
@@ -1400,7 +1400,7 @@ class PluginManagerPlugin(
"loglines": [{"line": line, "stream": stream} for line in lines],
},
)
for line in lines:
for line in lines: # noqa: B007
self._console_logger.debug("{prefix} {line}".format(**locals()))
def _mark_plugin_enabled(self, plugin, needs_restart=False):
@@ -874,7 +874,7 @@ class SoftwareUpdatePlugin(
if delete is None:
delete = []
for k, v in data.items():
for k in data:
if k in defaults and defaults[k] == data[k]:
delete.append(k)
+1 -1
View File
@@ -599,7 +599,7 @@ class Server(object):
kwargs["tags"] = tags
return f(*args, **kwargs)
setattr(wrapper, "__tagwrapped__", True)
wrapper.__tagwrapped__ = True
return wrapper
class TaggedFuncsPrinter(wrapt.ObjectProxy):
+2 -2
View File
@@ -80,7 +80,7 @@ def enable_additional_translations(default_locale="en", additional_folders=None)
# translations from plugins
plugins = octoprint.plugin.plugin_manager().enabled_plugins
for name, plugin in plugins.items():
for plugin in plugins.values():
plugin_translation_dir = os.path.join(plugin.location, "translations")
if not os.path.isdir(plugin_translation_dir):
continue
@@ -1127,7 +1127,7 @@ class PreemptiveCache(object):
if not isinstance(data, dict):
return False
for root, entries in data.items():
for entries in data.values():
if not isinstance(entries, list):
return False
+2 -2
View File
@@ -46,7 +46,7 @@ class ThreadSafeSession(octoprint.vendor.sockjs.tornado.session.Session):
return orig_send_pack(*args, **kwargs)
handler.send_pack = send_pack
setattr(handler, "__orig_send_pack", orig_send_pack)
handler.__orig_send_pack = orig_send_pack
return octoprint.vendor.sockjs.tornado.session.Session.set_handler(
self, handler, start_heartbeat=start_heartbeat
@@ -58,7 +58,7 @@ class ThreadSafeSession(octoprint.vendor.sockjs.tornado.session.Session):
)
if getattr(handler, "__orig_send_pack", None) is not None:
handler.send_pack = getattr(handler, "__orig_send_pack")
handler.send_pack = handler.__orig_send_pack
delattr(handler, "__orig_send_pack")
return result
+1 -1
View File
@@ -942,7 +942,7 @@ class Settings(object):
self._mtime = self.last_modified
except yaml.YAMLError as e:
details = e.message
details = str(e)
if hasattr(e, "problem_mark"):
line = e.problem_mark.line
+2 -2
View File
@@ -730,7 +730,7 @@ class Timelapse(object):
def _perform_capture(self, filename, onerror=None):
# pre-capture hook
for name, hook in self._pre_capture_hooks.items():
for hook in self._pre_capture_hooks.values():
try:
hook(filename)
except Exception:
@@ -771,7 +771,7 @@ class Timelapse(object):
err = None
# post-capture hook
for name, hook in self._post_capture_hooks.items():
for hook in self._post_capture_hooks.values():
try:
hook(filename, err is None)
except Exception:
+1 -1
View File
@@ -990,7 +990,7 @@ class fallback_dict(dict):
def values(self):
result = set()
for dictionary in self._all():
for k, v in dictionary.items():
for k in dictionary:
if k in result:
continue
result.add(k)
+3 -3
View File
@@ -534,13 +534,13 @@ class gcode(object):
)
if len(currentE) <= currentExtruder:
for i in range(len(currentE), currentExtruder + 1):
for _ in range(len(currentE), currentExtruder + 1):
currentE.append(0.0)
if len(maxExtrusion) <= currentExtruder:
for i in range(len(maxExtrusion), currentExtruder + 1):
for _ in range(len(maxExtrusion), currentExtruder + 1):
maxExtrusion.append(0.0)
if len(totalExtrusion) <= currentExtruder:
for i in range(len(totalExtrusion), currentExtruder + 1):
for _ in range(len(totalExtrusion), currentExtruder + 1):
totalExtrusion.append(0.0)
if throttle is not None:
+1 -1
View File
@@ -121,7 +121,7 @@ def get_all_template_paths(loader):
def walk_folder(folder):
files = []
walk_dir = walk(folder, followlinks=True)
for dirpath, dirnames, filenames in walk_dir:
for dirpath, _, filenames in walk_dir:
for filename in filenames:
path = os.path.join(dirpath, filename)
files.append(path)