Skip to content

Commit 7c2cff4

Browse files
dev: apply latest ruff linter rules
- remove S320 ignore since the rule was deleted
1 parent e77f2fd commit 7c2cff4

15 files changed

Lines changed: 23 additions & 34 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ ignore = [
7575
"F821", # undefined-name (doesn't work well with type hints, ruff 0.1.11).
7676
"PERF401", # manual-list-comprehension (false positives on selective transforms)
7777
"PERF402", # manual-list-copy (false positives on selective transforms)
78+
"PLC0415", # import-outside-top-level (pyxform has a few to avoid circular imports)
7879
"PLR0911", # too-many-return-statements (complexity not useful to warn every time)
7980
"PLR0912", # too-many-branches (complexity not useful to warn every time)
8081
"PLR0913", # too-many-arguments (complexity not useful to warn every time)
@@ -83,7 +84,6 @@ ignore = [
8384
"PLW2901", # redefined-loop-name (usually not a bug)
8485
"RUF001", # ambiguous-unicode-character-string (false positives on unicode tests)
8586
"S310", # suspicious-url-open-usage (prone to false positives, ruff 0.1.11)
86-
"S320", # suspicious-xmle-tree-usage (according to defusedxml author lxml is safe)
8787
"S603", # subprocess-without-shell-equals-true (prone to false positives, ruff 0.1.11)
8888
"TRY003", # raise-vanilla-args (reasonable lint but would require large refactor)
8989
]

pyxform/builder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,7 @@ def create_survey(
335335

336336
# assert name_of_main_section in sections, name_of_main_section
337337
if "id_string" not in main_section:
338-
main_section["id_string"] = (
339-
name_of_main_section if id_string is None else name_of_main_section
340-
)
338+
main_section["id_string"] = name_of_main_section
341339
survey = builder.create_survey_element_from_dict(main_section)
342340

343341
# not sure where to do this without repeating ourselves,

pyxform/instance.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,4 @@ def __unicode__(self):
9090
orphan_count = len(self._orphan_answers.keys())
9191
placed_count = len(self._answers.keys())
9292
answer_count = orphan_count + placed_count
93-
return "<Instance (%d answers: %d placed. %d orphans)>" % (
94-
answer_count,
95-
placed_count,
96-
orphan_count,
97-
)
93+
return f"<Instance ({answer_count} answers: {placed_count} placed. {orphan_count} orphans)>"

pyxform/parsing/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def tokenizer(scan, value) -> ExpLexerToken | str:
7777

7878

7979
class ExpLexerToken:
80-
__slots__ = ("name", "value", "start", "end")
80+
__slots__ = ("end", "name", "start", "value")
8181

8282
def __init__(self, name: str, value: str, start: int, end: int) -> None:
8383
self.name: str = name

pyxform/parsing/sheet_headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def merge_dicts(
5050
# Union keys but retain order (as opposed to set()), preferencing dict_a then dict_b.
5151
# E.g. {"a": 1, "b": 2} + {"c": 3, "a": 4} -> {"a": None, "b": None, "c": None}
5252
out_dict = dict_a
53-
for key in {k: None for k in (chain(dict_a, dict_b))}:
53+
for key in dict.fromkeys(chain(dict_a, dict_b)):
5454
out_dict[key] = merge_dicts(dict_a.get(key), dict_b.get(key), default_key)
5555
return out_dict
5656

@@ -66,7 +66,7 @@ def list_to_nested_dict(lst: Sequence) -> dict:
6666

6767

6868
class DealiasAndGroupHeadersResult:
69-
__slots__ = ("headers", "data")
69+
__slots__ = ("data", "headers")
7070

7171
def __init__(self, headers: tuple[tuple[str, ...], ...], data: Sequence[dict]):
7272
"""

pyxform/question.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def xml_instance(self, survey: "Survey", **kwargs):
146146

147147
def xml_control(self, survey: "Survey"):
148148
if self.type == "calculate" or (
149-
(self.bind is not None and "calculate" in self.bind or self.trigger)
149+
((self.bind is not None and "calculate" in self.bind) or self.trigger)
150150
and not (self.label or self.hint)
151151
):
152152
nested_setvalues = survey.get_trigger_values_for_question_name(

pyxform/survey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
class InstanceInfo:
4949
"""Standardise Instance details relevant during XML generation."""
5050

51-
__slots__ = ("type", "context", "name", "src", "instance")
51+
__slots__ = ("context", "instance", "name", "src", "type")
5252

5353
def __init__(
5454
self,

pyxform/survey_element.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def condition(e):
276276
reversed(tuple(i[0] for i in self.iter_ancestors(condition=condition))),
277277
self_element,
278278
)
279-
new_value = f'/{"/".join(n.name for n in lineage)}'
279+
new_value = f"/{'/'.join(n.name for n in lineage)}"
280280
self._survey_element_xpath = new_value
281281
return new_value
282282
return current_value
@@ -287,8 +287,7 @@ def _delete_keys_from_dict(self, dictionary: dict, keys: Iterable[str]):
287287
Credits: https://stackoverflow.com/a/49723101
288288
"""
289289
for key in keys:
290-
if key in dictionary:
291-
del dictionary[key]
290+
dictionary.pop(key, None)
292291

293292
for value in dictionary.values():
294293
if isinstance(value, dict):

pyxform/validators/updater.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _request_latest_json(url):
8787
@staticmethod
8888
def _check_path(file_path):
8989
if not os.path.exists(file_path):
90-
raise PyXFormError(f"Expected path does not exist: {file_path}" "")
90+
raise PyXFormError(f"Expected path does not exist: {file_path}")
9191
else:
9292
return True
9393

@@ -463,7 +463,7 @@ def check(update_info):
463463
:type update_info: _UpdateInfo
464464
"""
465465
if not os.path.exists(update_info.installed_path):
466-
message = "\nCheck failed!\n\n" "No installed release found."
466+
message = "\nCheck failed!\n\nNo installed release found."
467467
raise PyXFormError(message)
468468

469469
installed = _UpdateHandler._read_json(file_path=update_info.installed_path)
@@ -512,8 +512,7 @@ def _install_check(bin_file_path=None):
512512
class EnketoValidateUpdater(_UpdateService):
513513
def __init__(self):
514514
self.update_info = _UpdateInfo(
515-
api_url="https://api.github.com/repos/enketo/enketo-validate/"
516-
"releases/latest",
515+
api_url="https://api.github.com/repos/enketo/enketo-validate/releases/latest",
517516
repo_url="https://github.com/enketo/enketo-validate",
518517
validate_subfolder="enketo_validate",
519518
install_check=self._install_check,

pyxform/validators/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def request_get(url):
125125
) from http_err
126126
except URLError as url_err:
127127
raise PyXFormError(
128-
f"Unable to reach a server. Reason: {url_err.reason}. " f"URL: {url}"
128+
f"Unable to reach a server. Reason: {url_err.reason}. URL: {url}"
129129
) from url_err
130130

131131

0 commit comments

Comments
 (0)