Skip to content

Commit

Permalink
Fixed rest of the flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Sep 29, 2023
1 parent 7339b7d commit 15ce798
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 47 deletions.
5 changes: 2 additions & 3 deletions docs/examples/dynamic_mixin_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ def instantiate_and_print_results(d_cls, d_obj_name, header):
print(f'{d_obj_name}.__class__.__bases__={d_base_classes}')

for i in range(len(d_base_classes)):
print(
f'{d_obj_name}.__class__.__bases__[{i}].__bases__={d_obj.__class__.__bases__[i].__bases__}'
)
print(f'{d_obj_name}.__class__.__bases__[{i}].__bases__='
+ d_obj.__class__.__bases__[i].__bases__)

print()
print(f'{d_obj_name} = {d_cls.__name__}()')
Expand Down
24 changes: 12 additions & 12 deletions src/omnipy/compute/mixins/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def param_key_map(self) -> MappingProxyType[str, str]:

def _call_job(self, *args: object, **kwargs: object) -> object:
self_as_name_job_base_mixin = cast(NameJobBaseMixin, self)
self_signature_func_job_base_mixin = cast(SignatureFuncJobBaseMixin, self)
self_as_signature_func_job_base_mixin = cast(SignatureFuncJobBaseMixin, self)

mapped_fixed_params = self._param_key_mapper.delete_matching_keys(
self._fixed_params, inverse=True)
Expand All @@ -51,17 +51,17 @@ def _call_job(self, *args: object, **kwargs: object) -> object:

except TypeError as e:
if str(e).startswith('Incorrect job function arguments'):
raise TypeError(
f'Incorrect job function arguments for job "{self_as_name_job_base_mixin.name}"!\n'
f'Job class name: {self.__class__.__name__}\n'
f'Current parameter key map contents: {self.param_key_map}\n'
f'Positional arguments: {repr_max_len(args)}\n'
f'Keyword arguments: {repr_max_len(kwargs)}\n'
f'Mapped fixed parameters: {repr_max_len(mapped_fixed_params)}\n'
f'Mapped keyword arguments: {repr_max_len(mapped_kwargs)}\n'
f'Call function signature parameters: '
f'{[(str(p), p.kind) for p in self_signature_func_job_base_mixin.param_signatures.values()]}'
) from e
signature_values = self_as_signature_func_job_base_mixin.param_signatures.values()
raise TypeError(f'Incorrect job function arguments for job '
f'"{self_as_name_job_base_mixin.name}"!\n'
f'Job class name: {self.__class__.__name__}\n'
f'Current parameter key map contents: {self.param_key_map}\n'
f'Positional arguments: {repr_max_len(args)}\n'
f'Keyword arguments: {repr_max_len(kwargs)}\n'
f'Mapped fixed parameters: {repr_max_len(mapped_fixed_params)}\n'
f'Mapped keyword arguments: {repr_max_len(mapped_kwargs)}\n'
f'Call function signature parameters: '
f'{[(str(p), p.kind) for p in signature_values]}') from e
else:
raise

Expand Down
6 changes: 4 additions & 2 deletions src/omnipy/engine/job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def _register_job_state(self, job: IsJob, state: RunState) -> None:
if self._registry:
self._registry.set_job_state(job, state)

def _decorate_result_with_job_finalization_detector(self, job: IsJob, job_result: object):
def _decorate_result_with_job_finalization_detector( # noqa: C901
self, job: IsJob, job_result: object):
# TODO: Simplify _decorate_result_with_job_finalization_detector()
if isinstance(job_result, GeneratorType):
job_result = cast(GeneratorType, job_result)

Expand Down Expand Up @@ -148,7 +150,7 @@ def _dag_flow_runner_call_func(*args: object, **kwargs: object) -> Any:
job_callback_accept_decorator(_dag_flow_decorator)

@staticmethod
def default_dag_flow_run_decorator(dag_flow: IsDagFlow) -> Any:
def default_dag_flow_run_decorator(dag_flow: IsDagFlow) -> Any: # noqa: C901
def _inner_run_dag_flow(*args: object, **kwargs: object):
results = {}
result = None
Expand Down
7 changes: 4 additions & 3 deletions src/omnipy/util/callable_decorator_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from omnipy.api.types import DecoratorClassT


def callable_decorator_cls(cls: Type[DecoratorClassT]) -> IsCallableClass[DecoratorClassT]:
def callable_decorator_cls( # noqa: C901
cls: Type[DecoratorClassT]) -> IsCallableClass[DecoratorClassT]:
"""
"Meta-decorator" that allows any class to function as a decorator for a callable.
Expand Down Expand Up @@ -81,8 +82,8 @@ def _init(callable_arg: Callable) -> None:
_init(_callable_arg)
else:
# Add an instance-level _obj_call method, which are again callable by the
# class-level __call__ method. When this method is called, the provided _callable_arg
# is decorated.
# class-level __call__ method. When this method is called, the provided
# _callable_arg is decorated.
def _init_as_obj_call_method(
self, _callable_arg: Callable) -> Type[DecoratorClassT]: # noqa
_init(_callable_arg)
Expand Down
2 changes: 1 addition & 1 deletion src/omnipy/util/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __new__(cls, *args, **kwargs):
return obj

@classmethod
def _create_subcls_inheriting_from_mixins_and_orig_cls(cls):
def _create_subcls_inheriting_from_mixins_and_orig_cls(cls): # noqa: C901

# TODO: Refactor this, and possibly elsewhere in class

Expand Down
10 changes: 2 additions & 8 deletions tests/compute/helpers/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ def _call_job(self, *args: object, **kwargs: object) -> object:
...


#
# def mock_flow_template_callable_decorator_cls(
# cls: Type['MockFlowTemplateSubclass']
# ) -> IsFuncJobTemplateCallable['MockFlowTemplateSubclass']:
# return cast(IsFuncJobTemplateCallable['MockFlowTemplateSubclass'], callable_decorator_cls(cls))


# @callable_decorator_cls
class MockFlowTemplateSubclass(JobTemplateMixin, JobBase):
@classmethod
Expand Down Expand Up @@ -289,7 +282,8 @@ def reset_persisted_time_of_cur_toplevel_flow_run(cls) -> None:

def _call_func(self, *args: object, **kwargs: object) -> object:
if self.persisted_time_of_cur_toplevel_flow_run:
assert self.persisted_time_of_cur_toplevel_flow_run == self.time_of_cur_toplevel_flow_run
assert self.persisted_time_of_cur_toplevel_flow_run == \
self.time_of_cur_toplevel_flow_run
else:
self._persisted_time_of_cur_toplevel_flow_run.append(self.time_of_cur_toplevel_flow_run)

Expand Down
6 changes: 3 additions & 3 deletions tests/compute/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_linear_flow_template_as_decorator(
plus_five_template: LinearFlowTemplate,
) -> None:

assert (plus_five_template, LinearFlowTemplate)
assert isinstance(plus_five_template, LinearFlowTemplate)
assert plus_five_template.name == 'plus_five'

plus_five = plus_five_template.apply()
Expand All @@ -62,7 +62,7 @@ def test_dag_flow_template_as_decorator(
plus_five_template: DagFlowTemplate,
) -> None:

assert (plus_five_template, DagFlowTemplate)
assert isinstance(plus_five_template, DagFlowTemplate)
assert plus_five_template.name == 'plus_five'

plus_five = plus_five_template.apply()
Expand All @@ -86,7 +86,7 @@ def test_func_flow_template_as_decorator(
plus_y_template: FuncFlowTemplate,
) -> None:

assert (plus_y_template, FuncFlowTemplate)
assert isinstance(plus_y_template, FuncFlowTemplate)
assert plus_y_template.name == 'plus_y'

plus_y = plus_y_template.apply()
Expand Down
1 change: 0 additions & 1 deletion tests/hub/test_runtime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
from pathlib import Path
from typing import Annotated, Type
Expand Down
12 changes: 8 additions & 4 deletions tests/integration/novel/full/test_multi_model_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@


def test_table_models():
_a = GeneralTable([{'a': 123, 'b': 'ads'}, {'a': 234, 'b': 'acs'}])
_b = TableTemplate[MyRecordSchema]([{'a': 123, 'b': 'ads'}, {'a': 234, 'b': 'acs'}])
_a = GeneralTable([{'a': 123, 'b': 'ads'}, {'a': 234, 'b': 'acs'}]) # noqa: F841
# yapf: disable
_b = TableTemplate[MyRecordSchema]([{'a': 123, 'b': 'ads'}, # noqa: F841
{'a': 234, 'b': 'acs'}])

with pytest.raises(ValidationError):
_c = TableTemplate[MyOtherRecordSchema]([{'a': 123, 'b': 'ads'}, {'a': 234, 'b': 'acs'}])
_c = TableTemplate[MyOtherRecordSchema]([{'a': 123, 'b': 'ads'}, # noqa: F841
{'a': 234, 'b': 'acs'}])
# yapf: disable

# print(_a.to_json_schema(pretty=True))
# print(_b.to_json_schema(pretty=True))
Expand Down Expand Up @@ -138,4 +142,4 @@ def test_fail_run_specialize_record_models_inconsistent_types(
old_dataset['b'] = [{'b': 'df', 'c': True}, {'b': False, 'c': 'sg'}]

with pytest.raises(AssertionError):
_new_dataset = specialize_record_models(old_dataset)
_new_dataset = specialize_record_models(old_dataset) # noqa: F841
2 changes: 1 addition & 1 deletion tests/integration/novel/serialize/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PersistOutputsOptions,
RestoreOutputsOptions)
from omnipy.api.protocols.public.hub import IsRuntime
from omnipy.compute.task import FuncArgJobBase, TaskTemplate
from omnipy.compute.task import FuncArgJobBase


@pc.parametrize_with_cases('case_tmpl', cases='.cases.jobs', has_tag='task', prefix='case_config_')
Expand Down
3 changes: 0 additions & 3 deletions tests/log/helpers/functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from datetime import datetime
from io import StringIO
import os
from typing import List, Optional

from omnipy.util.helpers import get_datetime_format


def read_log_lines_from_stream(str_stream: StringIO) -> List[str]:
str_stream.seek(0)
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/pandas/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def test_pandas_dataset_list_of_objects_different_keys():
@pytest.mark.skipif(
os.getenv('OMNIPY_FORCE_SKIPPED_TEST') != '1',
reason="""
Pandas converts 'a' column into 'Int64' since all values can be cast into integers. Should remain
floats.
Pandas converts 'a' column into 'Int64' since all values can be cast into integers.
Should remain floats.
""")
def test_pandas_dataset_list_of_objects_float_numbers():
pandas_data = PandasDataset()
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/prefect/test_prefect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def test_no_prefect_console_handler_in_root_logger():
import omnipy.modules.prefect
import omnipy.modules.prefect # noqa: F401

assert os.environ['PREFECT_LOGGING_SETTINGS_PATH'].endswith('logging.yml')

Expand All @@ -14,7 +14,7 @@ def test_no_prefect_console_handler_in_root_logger():


def test_only_local_orion():
import omnipy.modules.prefect
import omnipy.modules.prefect # noqa: F401

assert os.environ['PREFECT_API_KEY'] == ''
assert os.environ['PREFECT_API_URL'] == ''
4 changes: 2 additions & 2 deletions tests/util/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Generic, get_args, get_type_hints, TypeVar
from typing import Dict, Generic, get_args, TypeVar

from typing_inspect import get_args, get_bound, get_generic_type, get_last_args, get_parameters
from typing_inspect import get_generic_type

from omnipy.util.helpers import transfer_generic_args_to_cls

Expand Down

0 comments on commit 15ce798

Please sign in to comment.