Skip to content

Commit f2c988e

Browse files
committed
Fixed a bunch of flake8 errors
1 parent b9ea8ff commit f2c988e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+222
-211
lines changed

scripts/omnipy_import.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
def omnipy_import() -> None:
2-
import omnipy
3-
import omnipy._dynamic_all
4-
omnipy.data
5-
from omnipy import Model
6-
import omnipy.data
7-
8-
# omnipy._dynamic_all.data
2+
import omnipy._dynamic_all # noqa: F401
93

104

115
omnipy_import()

src/omnipy/_dynamic_all.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
for module_name, module in _all_modules.items():
7878
for attr in dir(module):
79-
if not attr.startswith('_') and not attr in _all_element_names:
79+
if not attr.startswith('_') and attr not in _all_element_names:
8080
val = getattr(module, attr)
8181
if attr in _exclude_attrs:
8282
continue
@@ -90,20 +90,7 @@
9090
__all__.append(attr)
9191

9292
print(f'Missing elements in omnipy.__init__(): {_all_element_names - _omnipy_all}')
93-
print(
94-
f'Missing elements in hardcoded __all__ in _dynamic_all(): {_omnipy_all - _all_element_names}'
95-
)
93+
print(f'Missing elements in hardcoded __all__ in _dynamic_all(): '
94+
f'{_omnipy_all - _all_element_names}')
9695

9796
del JobTemplateMixin
98-
99-
# from omnipy import __all__ as prev_all
100-
#
101-
# prev_all_set = set(prev_all)
102-
#
103-
# print(f'__all__: {__all__}')
104-
# print(
105-
# f'_all_element_names - prev_all: {[_ for _ in __all__ if _ in (_all_element_names - prev_all_set)]}'
106-
# )
107-
# print(
108-
# f'prev_all - _all_element_names: {[_ for _ in prev_all if _ in (prev_all_set - _all_element_names)]}'
109-
# )

src/omnipy/api/protocols/private/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from omnipy.api.protocols.public.config import IsDataConfig
55

66
_ObjT = TypeVar('_ObjT', bound=object)
7-
_ContentsT = TypeVar("_ContentsT", bound=object)
7+
_ContentsT = TypeVar('_ContentsT', bound=object)
88

99

1010
class IsDataClassCreator(Protocol[_ObjT, _ContentsT]):

src/omnipy/api/protocols/private/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
_ObjContraT = TypeVar('_ObjContraT', contravariant=True, bound=object)
88
_AnyKeyT = TypeVar('_AnyKeyT', contravariant=True, bound=object)
99
_ValT = TypeVar('_ValT', bound=object)
10-
_ContentsT = TypeVar("_ContentsT", bound=object)
11-
_ContentCovT = TypeVar("_ContentCovT", covariant=True, bound=object)
12-
_ContentContraT = TypeVar("_ContentContraT", contravariant=True, bound=object)
10+
_ContentsT = TypeVar('_ContentsT', bound=object)
11+
_ContentCovT = TypeVar('_ContentCovT', covariant=True, bound=object)
12+
_ContentContraT = TypeVar('_ContentContraT', contravariant=True, bound=object)
1313
_HasContentsT = TypeVar('_HasContentsT', bound='HasContents')
1414

1515

src/omnipy/data/data_class_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABCMeta
22
from contextlib import contextmanager
3-
from typing import Callable, ContextManager, Generic, Iterator, TypeVar
3+
from typing import Callable, ContextManager, Iterator
44

55
from omnipy.api.protocols.private.data import IsDataClassCreator
66
from omnipy.api.protocols.private.util import IsSnapshotHolder

src/omnipy/data/dataset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,13 @@ def load(self, *path_or_urls: str, by_file_suffix=False):
530530
raise ValueError(f'Unsupported scheme "{parsed_url.scheme}"')
531531

532532
if by_file_suffix:
533-
loaded_dataset = serializer_registry.load_from_tar_file_path_based_on_file_suffix(
534-
self, tar_gz_file_path, self)
533+
loaded_dataset = \
534+
serializer_registry.load_from_tar_file_path_based_on_file_suffix(
535+
self, tar_gz_file_path, self)
535536
else:
536-
loaded_dataset = serializer_registry.load_from_tar_file_path_based_on_dataset_cls(
537-
self, tar_gz_file_path, self)
537+
loaded_dataset = \
538+
serializer_registry.load_from_tar_file_path_based_on_dataset_cls(
539+
self, tar_gz_file_path, self)
538540
if loaded_dataset is not None:
539541
self.absorb(loaded_dataset)
540542
continue

src/omnipy/data/missing.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,18 @@ def parse_none_according_to_model(value: _RootT, root_model) -> _RootT: # IsMod
4343
raise OmnipyNoneIsNotAllowedError()
4444

4545
else:
46-
union_variant_types = _split_outer_type_to_union_variants(outer_args)
47-
flattened_union_variant_types = _flatten_two_level_tuple(union_variant_types)
46+
union_variants = _split_outer_type_to_union_variants(outer_args)
47+
flattened_union_variants = _flatten_two_level_tuple(union_variants)
4848

49-
if any(is_model_subclass(type_) or _supports_none(type_) \
50-
for type_ in flattened_union_variant_types):
49+
if any(is_model_subclass(tp_) or _supports_none(tp_) for tp_ in flattened_union_variants):
5150

5251
# Fixed tuples
5352
if _outer_type_and_value_are_of_types(plain_outer_type, value, tuple) and outer_args:
54-
return _parse_none_in_fixed_tuple(plain_outer_type, union_variant_types, value)
53+
return _parse_none_in_fixed_tuple(plain_outer_type, union_variants, value)
5554

5655
# Unions
5756
if is_union(plain_outer_type):
58-
return _parse_none_in_union(flattened_union_variant_types, value)
57+
return _parse_none_in_union(flattened_union_variants, value)
5958

6059
return value
6160

@@ -81,8 +80,9 @@ def _supports_none(type_: TypeForm) -> bool:
8180

8281

8382
def _outer_type_and_value_are_of_types(plain_outer_type, value, *types):
84-
return any(lenient_issubclass(plain_outer_type, type_) and lenient_isinstance(value, type_) \
85-
for type_ in types)
83+
return any(
84+
lenient_issubclass(plain_outer_type, type_) and lenient_isinstance(value, type_)
85+
for type_ in types)
8686

8787

8888
def _parse_none_in_mutable_sequence_or_tuple(plain_outer_type, inner_val_type, value):
@@ -101,7 +101,8 @@ def _parse_none_in_mapping(plain_outer_type, outer_type_args, inner_val_type, va
101101
plain_outer_type, Mapping) and outer_type_args else Undefined
102102
inner_key_union_types = _split_to_union_variants(inner_key_type)
103103

104-
if any(is_model_subclass(_) or _supports_none(_) \
104+
if any(
105+
is_model_subclass(_) or _supports_none(_)
105106
for _ in chain(inner_key_union_types, inner_val_union_types)):
106107
return plain_outer_type({
107108
_parse_none_in_types(inner_key_union_types) if key is None else key:

src/omnipy/data/model.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ def default_factory() -> _RootT:
160160
return default_factory
161161

162162
@classmethod
163-
def _get_default_value_from_model(cls, model: type[_RootT] | TypeForm | TypeVar) -> _RootT:
163+
def _get_default_value_from_model( # noqa: C901
164+
cls,
165+
model: type[_RootT] | TypeForm | TypeVar,
166+
) -> _RootT:
164167
model = get_default_if_typevar(model)
165168
origin_type = get_origin(model)
166169
args = get_args(model)
@@ -322,7 +325,7 @@ def set_orig_model(cls, orig_model: type[_RootT]) -> None:
322325

323326
# TODO: Allow e.g. Model[str](Model[int](5)) == Model[str](Model[int](5).contents).
324327
# Should then work the same as dataset
325-
def __init__(
328+
def __init__( # noqa: C901
326329
self,
327330
value: Any | UndefinedType = Undefined,
328331
*,
@@ -509,9 +512,9 @@ def _prepare_reset_solution_take_snapshot_if_needed(
509512
snapshot_taken = False
510513
if self.config.interactive_mode:
511514
# TODO: Lazy snapshotting causes unneeded double validation for data that is later
512-
# validated for snapshot. Perhaps add a dirty flag to snapshot that can be used to
513-
# determine if re-validation is needed? This can also help avoid equality tests, which
514-
# might be expensive for large data structures.
515+
# validated for snapshot. Perhaps add a dirty flag to snapshot that can be used
516+
# to determine if re-validation is needed? This can also help avoid equality
517+
# tests, which might be expensive for large data structures.
515518
needs_pre_validation = (not self.has_snapshot()
516519
or not self.contents_validated_according_to_snapshot())
517520
if needs_pre_validation:
@@ -622,7 +625,7 @@ def snapshot_differs_from_model(self, model: 'Model') -> bool:
622625

623626
def contents_validated_according_to_snapshot(self) -> bool:
624627
needs_validation = self.snapshot_differs_from_model(self) \
625-
or not self.snapshot_taken_of_same_model(self)
628+
or not self.snapshot_taken_of_same_model(self)
626629
return not needs_validation
627630

628631
def _take_snapshot_of_validated_contents(self) -> None:
@@ -878,7 +881,12 @@ def _call_special_method_and_return_self_if_inplace(*inner_args: object,
878881

879882
return ret
880883

881-
def _call_special_method(self, name: str, *args: object, **kwargs: object) -> object:
884+
def _call_special_method( # noqa: C901
885+
self,
886+
name: str,
887+
*args: object,
888+
**kwargs: object,
889+
) -> object:
882890
contents = self._get_real_contents()
883891
has_add_method = hasattr(contents, '__add__')
884892
has_radd_method = hasattr(contents, '__radd__')
@@ -1027,12 +1035,14 @@ def _get_convert_element_value_model_generator(
10271035
self, elements: Iterable | None) -> Callable[..., Generator]:
10281036
def _convert_element_value_model_generator(elements=elements):
10291037
for el in elements:
1030-
yield (el[0],
1031-
self._convert_to_model_if_reasonable(
1032-
el[1],
1033-
level_up=True,
1034-
level_up_arg_idx=1,
1035-
))
1038+
yield (
1039+
el[0],
1040+
self._convert_to_model_if_reasonable(
1041+
el[1],
1042+
level_up=True,
1043+
level_up_arg_idx=1,
1044+
),
1045+
)
10361046

10371047
return _convert_element_value_model_generator
10381048

@@ -1142,7 +1152,6 @@ def _validate_contents(ret: Any):
11421152
reset_solution)
11431153

11441154
if attr in ('values', 'items'):
1145-
level_up_arg_idx: int | slice
11461155
match attr:
11471156
case 'values':
11481157
_model_generator = self._get_convert_full_element_model_generator(

src/omnipy/data/param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(cls, name: str, bases: tuple[type, ...], namespace: dict[str, objec
2121
default_vals = {}
2222
for field in model_cls.__fields__.values():
2323
if field.default_factory is not None:
24-
raise ValueError(f"Default factory is not supported for Params classes")
24+
raise ValueError('Default factory is not supported for Params classes')
2525

2626
default_vals[field.name] = field.get_default()
2727
if default_vals[field.name] is None and not field.allow_none:

src/omnipy/data/selector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import defaultdict
22
from dataclasses import dataclass
3-
from typing import Iterable, Mapping, MutableMapping, TypeAlias
3+
from typing import Iterable, MutableMapping, TypeAlias
44

55
from typing_extensions import TypeVar
66

0 commit comments

Comments
 (0)