From ec8d6aedb8b1350b97c97ceb8a03e629b65413d8 Mon Sep 17 00:00:00 2001 From: Sveinung Gundersen Date: Thu, 5 Dec 2024 16:26:31 +0100 Subject: [PATCH] Updated pre-commit tools. Fixed linting --- .pre-commit-config.yaml | 4 ++-- src/omnipy/data/dataset.py | 4 ++-- src/omnipy/data/missing.py | 8 +++---- src/omnipy/data/mixins/task.py | 5 ++-- src/omnipy/util/mixin.py | 4 ++-- src/omnipy/util/tabulate/__init__.py | 35 +++++++++++++--------------- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d3ae996f..bb1d3095 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-yaml types: [ yaml ] @@ -14,7 +14,7 @@ repos: hooks: - id: poetry-check - repo: https://github.com/google/yapf - rev: v0.40.2 + rev: v0.43.0 hooks: - id: yapf name: "yapf" diff --git a/src/omnipy/data/dataset.py b/src/omnipy/data/dataset.py index 1f89e473..ec743b10 100644 --- a/src/omnipy/data/dataset.py +++ b/src/omnipy/data/dataset.py @@ -447,8 +447,8 @@ def _parse_root_object(cls, root_obj: dict[str, ModelT]) -> Any: # noqa def to_data(self) -> dict[str, Any]: return { - key: self._check_value(val) for key, - val in GenericModel.dict(self, by_alias=True).get(DATA_KEY).items() + key: self._check_value(val) + for key, val in GenericModel.dict(self, by_alias=True).get(DATA_KEY).items() } def from_data(self, diff --git a/src/omnipy/data/missing.py b/src/omnipy/data/missing.py index 4e4bc863..883eb07f 100644 --- a/src/omnipy/data/missing.py +++ b/src/omnipy/data/missing.py @@ -106,8 +106,8 @@ def _parse_none_in_mapping(plain_outer_type, outer_type_args, inner_val_type, va for _ in chain(inner_key_union_types, inner_val_union_types)): return plain_outer_type({ _parse_none_in_types(inner_key_union_types) if key is None else key: - _parse_none_in_types(inner_val_union_types) if val is None else val for key, - val in value.items() + _parse_none_in_types(inner_val_union_types) if val is None else val + for key, val in value.items() }) return value @@ -120,8 +120,8 @@ def _parse_none_in_typevar(inner_val_type): def _parse_none_in_fixed_tuple(plain_outer_type, tuple_of_union_variant_types, value): return plain_outer_type( - _parse_none_in_types(tuple_of_union_variant_types[i]) if val is None else val for i, - val in enumerate(value)) + _parse_none_in_types(tuple_of_union_variant_types[i]) if val is None else val + for i, val in enumerate(value)) def _parse_none_in_union(flattened_union_variant_types, value): diff --git a/src/omnipy/data/mixins/task.py b/src/omnipy/data/mixins/task.py index f57a7dab..91206425 100644 --- a/src/omnipy/data/mixins/task.py +++ b/src/omnipy/data/mixins/task.py @@ -38,8 +38,9 @@ def available_data(self) -> IsDataset[type[ModelT]]: self_with_data = cast(HasData, self) copy = cast(HasData, self.__class__()) copy.data = { - key: val for key, - val in self_with_data.data.items() if not isinstance(val, (PendingData, FailedData)) + key: val + for key, val in self_with_data.data.items() + if not isinstance(val, (PendingData, FailedData)) } return cast(IsDataset[type[ModelT]], copy) diff --git a/src/omnipy/util/mixin.py b/src/omnipy/util/mixin.py index 7b91699f..b8cf30ad 100644 --- a/src/omnipy/util/mixin.py +++ b/src/omnipy/util/mixin.py @@ -32,8 +32,8 @@ def __init_subclass__(cls, **kwargs): @classmethod def _get_mixin_init_kwarg_params(cls) -> dict[str, inspect.Parameter]: return { - key: param for param_dict in cls._init_params_per_mixin_cls.values() for key, - param in param_dict.items() + key: param for param_dict in cls._init_params_per_mixin_cls.values() + for key, param in param_dict.items() } @property diff --git a/src/omnipy/util/tabulate/__init__.py b/src/omnipy/util/tabulate/__init__.py index 3a781c97..4d167fe1 100644 --- a/src/omnipy/util/tabulate/__init__.py +++ b/src/omnipy/util/tabulate/__init__.py @@ -169,13 +169,13 @@ def _html_row_with_attrs(celltag, unsafe, cell_values, colwidths, colaligns): } if unsafe: values_with_attrs = [ - "<{0}{1}>{2}".format(celltag, alignment.get(a, ""), c) for c, - a in zip(cell_values, colaligns) + "<{0}{1}>{2}".format(celltag, alignment.get(a, ""), c) + for c, a in zip(cell_values, colaligns) ] else: values_with_attrs = [ - "<{0}{1}>{2}".format(celltag, alignment.get(a, ""), htmlescape(c)) for c, - a in zip(cell_values, colaligns) + "<{0}{1}>{2}".format(celltag, alignment.get(a, ""), htmlescape(c)) + for c, a in zip(cell_values, colaligns) ] rowhtml = "{}".format("".join(values_with_attrs).rstrip()) if celltag == "th": # it's a header row, create a new table header @@ -191,8 +191,8 @@ def _moin_row_with_attrs(celltag, cell_values, colwidths, colaligns, header=""): "decimal": '', } values_with_attrs = [ - "{}{} {} ".format(celltag, alignment.get(a, ""), header + c + header) for c, - a in zip(cell_values, colaligns) + "{}{} {} ".format(celltag, alignment.get(a, ""), header + c + header) + for c, a in zip(cell_values, colaligns) ] return "".join(values_with_attrs) + "||" @@ -1162,8 +1162,9 @@ def _align_column( # wcswidth and _visible_width don't count invisible characters; # padfn doesn't need to apply another correction padded_strings = [ - "\n".join([padfn(w, s) for s, w in zip((ms.splitlines() or ms), mw)]) for ms, - mw in zip(strings, visible_widths) + "\n".join([padfn(w, s) + for s, w in zip((ms.splitlines() or ms), mw)]) + for ms, mw in zip(strings, visible_widths) ] else: # single-line cell values if not enable_widechars and not has_invisible: @@ -2163,11 +2164,9 @@ def tabulate( missing_vals = list(missingval) if len(missing_vals) < len(cols): missing_vals.extend((len(cols) - len(missing_vals)) * [_DEFAULT_MISSINGVAL]) - cols = [[_format(v, ct, fl_fmt, int_fmt, miss_v, has_invisible) for v in c] for c, - ct, - fl_fmt, - int_fmt, - miss_v in zip(cols, coltypes, float_formats, int_formats, missing_vals)] + cols = [[_format(v, ct, fl_fmt, int_fmt, miss_v, + has_invisible) for v in c] for c, ct, fl_fmt, int_fmt, miss_v in zip( + cols, coltypes, float_formats, int_formats, missing_vals)] # align columns # first set global alignment @@ -2189,9 +2188,8 @@ def tabulate( aligns[idx] = align minwidths = ([width_fn(h) + min_padding for h in headers] if headers else [0] * len(cols)) cols = [ - _align_column(c, a, minw, has_invisible, enable_widechars, is_multiline) for c, - a, - minw in zip(cols, aligns, minwidths) + _align_column(c, a, minw, has_invisible, enable_widechars, is_multiline) + for c, a, minw in zip(cols, aligns, minwidths) ] aligns_headers = None @@ -2220,9 +2218,8 @@ def tabulate( aligns_headers[hidx] = align minwidths = [max(minw, max(width_fn(cl) for cl in c)) for minw, c in zip(minwidths, t_cols)] headers = [ - _align_header(h, a, minw, width_fn(h), is_multiline, width_fn) for h, - a, - minw in zip(headers, aligns_headers, minwidths) + _align_header(h, a, minw, width_fn(h), is_multiline, width_fn) + for h, a, minw in zip(headers, aligns_headers, minwidths) ] rows = list(zip(*cols)) else: