Skip to content

Commit

Permalink
use flake8-bugbear for linting (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades authored Nov 30, 2021
1 parent 4416782 commit 254c107
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- pep8-naming

- repo: https://github.com/pycqa/isort
Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/needs/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/needs/directives/needextend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/needs/directives/needimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions sphinxcontrib/needs/directives/needtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/needs/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions sphinxcontrib/needs/roles/need_incoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]):
Expand Down
4 changes: 2 additions & 2 deletions sphinxcontrib/needs/roles/need_outgoing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/needs/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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

Expand Down

0 comments on commit 254c107

Please sign in to comment.