From 254c10709ac0560e3c3d1fe66f99c85f5342bc6e Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Tue, 30 Nov 2021 07:48:18 +0000 Subject: [PATCH] use flake8-bugbear for linting (#416) --- .pre-commit-config.yaml | 1 + sphinxcontrib/needs/builder.py | 6 +++--- sphinxcontrib/needs/directives/needextend.py | 2 +- sphinxcontrib/needs/directives/needimport.py | 6 +++--- sphinxcontrib/needs/directives/needtable.py | 8 ++++---- sphinxcontrib/needs/layout.py | 2 +- sphinxcontrib/needs/roles/need_incoming.py | 4 ++-- sphinxcontrib/needs/roles/need_outgoing.py | 4 ++-- sphinxcontrib/needs/warnings.py | 6 +++--- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c35bdde51..6402a5e41 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,7 @@ repos: hooks: - id: flake8 additional_dependencies: + - flake8-bugbear - pep8-naming - repo: https://github.com/pycqa/isort diff --git a/sphinxcontrib/needs/builder.py b/sphinxcontrib/needs/builder.py index ed5685105..98f232f24 100644 --- a/sphinxcontrib/needs/builder.py +++ b/sphinxcontrib/needs/builder.py @@ -24,8 +24,8 @@ def finish(self): version = config.version needs_list = NeedsList(config, self.outdir, self.confdir) - if getattr(config, "needs_file"): - needs_file = getattr(config, "needs_file") + if config.needs_file: + needs_file = config.needs_file needs_list.load_json(needs_file) else: # check if needs.json file exists in conf.py directory @@ -46,7 +46,7 @@ def finish(self): for need in filtered_needs: needs_list.add_need(version, need) - for key, need_filter in filters.items(): + for need_filter in filters.values(): if need_filter["export_id"]: needs_list.add_filter(version, need_filter) diff --git a/sphinxcontrib/needs/directives/needextend.py b/sphinxcontrib/needs/directives/needextend.py index f86dfc570..cd7634298 100644 --- a/sphinxcontrib/needs/directives/needextend.py +++ b/sphinxcontrib/needs/directives/needextend.py @@ -74,7 +74,7 @@ def process_needextend(app, doctree, fromdocname): ) # back-links (incoming) link_names = [x["option"] for x in app.config.needs_extra_links] - for extend_name, current_needextend in env.need_all_needextend.items(): + for current_needextend in env.need_all_needextend.values(): # Check if filter is just a need-id. # In this case create the needed filter string diff --git a/sphinxcontrib/needs/directives/needimport.py b/sphinxcontrib/needs/directives/needimport.py index cc9507a41..344dc0c9a 100644 --- a/sphinxcontrib/needs/directives/needimport.py +++ b/sphinxcontrib/needs/directives/needimport.py @@ -126,7 +126,7 @@ def run(self): if id_prefix: needs_ids = needs_list.keys() - for key, need in needs_list.items(): + for need in needs_list.values(): for id in needs_ids: # Manipulate links in all link types for extra_link in env.config.needs_extra_links: @@ -139,11 +139,11 @@ def run(self): need["description"] = need["description"].replace(id, "".join([id_prefix, id])) # tags update - for key, need in needs_list.items(): + for need in needs_list.values(): need["tags"] = need["tags"] + tags need_nodes = [] - for key, need in needs_list.items(): + for need in needs_list.values(): # Set some values based on given option or value from imported need. need["template"] = self.options.get("template", getattr(need, "template", None)) need["pre_template"] = self.options.get("pre_template", getattr(need, "pre_template", None)) diff --git a/sphinxcontrib/needs/directives/needtable.py b/sphinxcontrib/needs/directives/needtable.py index 9d4bf0815..3aaf2cb87 100644 --- a/sphinxcontrib/needs/directives/needtable.py +++ b/sphinxcontrib/needs/directives/needtable.py @@ -155,14 +155,14 @@ def process_needtables(app, doctree, fromdocname): # Define Table column width # ToDo: Find a way to chosen to perfect width automatically. - for option, title in current_needtable["columns"]: + for option, _title in current_needtable["columns"]: if option == "TITLE": tgroup += nodes.colspec(colwidth=15) else: tgroup += nodes.colspec(colwidth=5) node_columns = [] - for option, title in current_needtable["columns"]: + for _option, title in current_needtable["columns"]: header_name = title node_columns.append(nodes.entry("", nodes.paragraph("", header_name))) @@ -216,7 +216,7 @@ def sort(need): prefix = app.config.needs_part_prefix temp_need["title"] = temp_need["content"] - for option, title in current_needtable["columns"]: + for option, _title in current_needtable["columns"]: if option == "ID": row += row_col_maker( app, fromdocname, env.needs_all_needs, temp_need, "id", make_ref=True, prefix=prefix @@ -259,7 +259,7 @@ def sort(need): row = nodes.row(classes=["need_part"]) - for option, title in current_needtable["columns"]: + for option, _title in current_needtable["columns"]: if option == "ID": row += row_col_maker( app, diff --git a/sphinxcontrib/needs/layout.py b/sphinxcontrib/needs/layout.py index d7f4882a8..d9ebf654c 100644 --- a/sphinxcontrib/needs/layout.py +++ b/sphinxcontrib/needs/layout.py @@ -453,7 +453,7 @@ def meta(self, name, prefix=None, show_empty=False): # data_container.append(data_node) matching_link_confs = [] - for link_name, link_conf in self.string_links.items(): + for link_conf in self.string_links.values(): if name in link_conf["options"]: matching_link_confs.append(link_conf) diff --git a/sphinxcontrib/needs/roles/need_incoming.py b/sphinxcontrib/needs/roles/need_incoming.py index 60ee04168..c63c185c1 100644 --- a/sphinxcontrib/needs/roles/need_incoming.py +++ b/sphinxcontrib/needs/roles/need_incoming.py @@ -30,11 +30,11 @@ def process_need_incoming(app, doctree, fromdocname): if back_link in env.needs_all_needs: try: target_need = env.needs_all_needs[back_link] - if getattr(env.config, "needs_show_link_title"): + if env.config.needs_show_link_title: link_text = "{title} ({id})".format(title=target_need["title"], id=target_need["id"]) else: link_text = target_need["id"] - if getattr(env.config, "needs_show_link_type"): + if env.config.needs_show_link_type: link_text += " [{type}]".format(type=target_need["type_name"]) # if index + 1 < len(ref_need["links_back"]): diff --git a/sphinxcontrib/needs/roles/need_outgoing.py b/sphinxcontrib/needs/roles/need_outgoing.py index c2c950fbe..fb060d03f 100644 --- a/sphinxcontrib/needs/roles/need_outgoing.py +++ b/sphinxcontrib/needs/roles/need_outgoing.py @@ -53,11 +53,11 @@ def process_need_outgoing(app, doctree, fromdocname): target_title = target_need["title"] target_id = target_need["id"] - if getattr(env.config, "needs_show_link_title"): + if env.config.needs_show_link_title: link_text = "{title} ({id})".format(title=target_title, id=target_id) else: link_text = target_id - if getattr(env.config, "needs_show_link_type"): + if env.config.needs_show_link_type: link_text += " [{type}]".format(type=target_need["type_name"]) node_need_ref[0] = nodes.Text(link_text, link_text) diff --git a/sphinxcontrib/needs/warnings.py b/sphinxcontrib/needs/warnings.py index 9f02c57bc..c2d916ca9 100644 --- a/sphinxcontrib/needs/warnings.py +++ b/sphinxcontrib/needs/warnings.py @@ -58,7 +58,7 @@ def process_warnings(app, exception): if isinstance(warning_filter, str): # filter string used result = filter_needs(app, checked_needs.values(), warning_filter) - elif hasattr(warning_filter, "__call__"): + elif callable(warning_filter): # custom defined filter code used from conf.py result = [] for need in checked_needs.values(): @@ -83,8 +83,8 @@ def process_warnings(app, exception): app.statuscode = 1 # get the text for used filter, either from filter string or function name - if hasattr(warning_filter, "__call__"): - warning_text = getattr(warning_filter, "__name__") + if callable(warning_filter): + warning_text = warning_filter.__name__ elif isinstance(warning_filter, str): warning_text = warning_filter