diff --git a/docs/examples/dynamic_mixin_example.py b/docs/examples/dynamic_mixin_example.py index efb0a3de..3324f54b 100644 --- a/docs/examples/dynamic_mixin_example.py +++ b/docs/examples/dynamic_mixin_example.py @@ -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__}()') diff --git a/src/omnipy/compute/mixins/params.py b/src/omnipy/compute/mixins/params.py index ac341204..b626afca 100644 --- a/src/omnipy/compute/mixins/params.py +++ b/src/omnipy/compute/mixins/params.py @@ -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) @@ -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 diff --git a/src/omnipy/engine/job_runner.py b/src/omnipy/engine/job_runner.py index 2bbec656..933f1cff 100644 --- a/src/omnipy/engine/job_runner.py +++ b/src/omnipy/engine/job_runner.py @@ -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) @@ -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 diff --git a/src/omnipy/util/callable_decorator_cls.py b/src/omnipy/util/callable_decorator_cls.py index 26e982ae..d9bb33ff 100644 --- a/src/omnipy/util/callable_decorator_cls.py +++ b/src/omnipy/util/callable_decorator_cls.py @@ -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. @@ -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) diff --git a/src/omnipy/util/mixin.py b/src/omnipy/util/mixin.py index 3365c6dc..75d52c9e 100644 --- a/src/omnipy/util/mixin.py +++ b/src/omnipy/util/mixin.py @@ -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 diff --git a/tests/compute/helpers/mocks.py b/tests/compute/helpers/mocks.py index 899afe4e..08516b11 100644 --- a/tests/compute/helpers/mocks.py +++ b/tests/compute/helpers/mocks.py @@ -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 @@ -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) diff --git a/tests/compute/test_decorators.py b/tests/compute/test_decorators.py index 3d053c91..67e5a642 100644 --- a/tests/compute/test_decorators.py +++ b/tests/compute/test_decorators.py @@ -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() @@ -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() @@ -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() diff --git a/tests/hub/test_runtime.py b/tests/hub/test_runtime.py index d5feeed2..18205dde 100644 --- a/tests/hub/test_runtime.py +++ b/tests/hub/test_runtime.py @@ -1,4 +1,3 @@ -import logging import os from pathlib import Path from typing import Annotated, Type diff --git a/tests/integration/novel/full/test_multi_model_dataset.py b/tests/integration/novel/full/test_multi_model_dataset.py index 6089bc41..fed9de06 100644 --- a/tests/integration/novel/full/test_multi_model_dataset.py +++ b/tests/integration/novel/full/test_multi_model_dataset.py @@ -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)) @@ -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 diff --git a/tests/integration/novel/serialize/test_serialize.py b/tests/integration/novel/serialize/test_serialize.py index 14f18d26..51db6716 100644 --- a/tests/integration/novel/serialize/test_serialize.py +++ b/tests/integration/novel/serialize/test_serialize.py @@ -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_') diff --git a/tests/log/helpers/functions.py b/tests/log/helpers/functions.py index c3614faa..fb1534d7 100644 --- a/tests/log/helpers/functions.py +++ b/tests/log/helpers/functions.py @@ -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) diff --git a/tests/modules/pandas/test_pandas.py b/tests/modules/pandas/test_pandas.py index 9509bdbc..475b2cb9 100644 --- a/tests/modules/pandas/test_pandas.py +++ b/tests/modules/pandas/test_pandas.py @@ -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() diff --git a/tests/modules/prefect/test_prefect.py b/tests/modules/prefect/test_prefect.py index 8103632e..969391f8 100644 --- a/tests/modules/prefect/test_prefect.py +++ b/tests/modules/prefect/test_prefect.py @@ -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') @@ -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'] == '' diff --git a/tests/util/test_helpers.py b/tests/util/test_helpers.py index 2f292821..9911473c 100644 --- a/tests/util/test_helpers.py +++ b/tests/util/test_helpers.py @@ -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