diff --git a/sdk/python/kfp/compiler/compiler_test.py b/sdk/python/kfp/compiler/compiler_test.py index 19b84aeed94..a66ca2ce6f4 100644 --- a/sdk/python/kfp/compiler/compiler_test.py +++ b/sdk/python/kfp/compiler/compiler_test.py @@ -601,7 +601,7 @@ def pipeline_hello_world(text: str = 'hi there'): v2.compiler.Compiler().compile( pipeline_func=pipeline_hello_world, package_path=temp_filepath) - with open(temp_filepath, "r") as f: + with open(temp_filepath, 'r') as f: yaml.load(f) def test_import_modules(self): # pylint: disable=no-self-use @@ -625,7 +625,7 @@ def pipeline_hello_world(text: str = 'hi there'): compiler.Compiler().compile( pipeline_func=pipeline_hello_world, package_path=temp_filepath) - with open(temp_filepath, "r") as f: + with open(temp_filepath, 'r') as f: yaml.load(f) def test_import_object(self): # pylint: disable=no-self-use @@ -650,7 +650,7 @@ def pipeline_hello_world(text: str = 'hi there'): Compiler().compile( pipeline_func=pipeline_hello_world, package_path=temp_filepath) - with open(temp_filepath, "r") as f: + with open(temp_filepath, 'r') as f: yaml.load(f) @@ -670,8 +670,8 @@ def my_pipeline(): return my_pipeline @parameterized.parameters( - {"extension": ".yaml"}, - {"extension": ".yml"}, + {'extension': '.yaml'}, + {'extension': '.yml'}, ) def test_can_write_to_yaml(self, extension): @@ -701,7 +701,7 @@ def test_can_write_to_json(self): target_file = os.path.join(tmpdir, 'result.json') with self.assertWarnsRegex(DeprecationWarning, - r"Compiling to JSON is deprecated"): + r'Compiling to JSON is deprecated'): compiler.Compiler().compile( pipeline_func=pipeline_spec, package_path=target_file) with open(target_file) as f: @@ -745,7 +745,7 @@ def test_compile_pipeline_with_default_value(self): @dsl.pipeline(name='test-pipeline') def simple_pipeline(): - producer = producer_op(location="1", nodefault="string") + producer = producer_op(location='1', nodefault='string') target_json_file = os.path.join(tmpdir, 'result.json') compiler.Compiler().compile( diff --git a/sdk/python/kfp/components/base_component.py b/sdk/python/kfp/components/base_component.py index a6491a530c5..e84068e1de8 100644 --- a/sdk/python/kfp/components/base_component.py +++ b/sdk/python/kfp/components/base_component.py @@ -40,11 +40,11 @@ def __init__(self, component_spec: structures.ComponentSpec): # Arguments typed as PipelineTaskFinalStatus are special arguments that # do not count as user inputs. Instead, they are reserved to for the # (backend) system to pass a value. - self._component_inputs = set([ + self._component_inputs = { input_name for input_name, input_spec in ( self.component_spec.inputs or {}).items() if not type_utils.is_task_final_status_type(input_spec.type) - ]) + } def __call__(self, *args, **kwargs) -> pipeline_task.PipelineTask: """Creates a PipelineTask object. diff --git a/sdk/python/kfp/components/base_component_test.py b/sdk/python/kfp/components/base_component_test.py index bb1c33d0896..548fb34332d 100644 --- a/sdk/python/kfp/components/base_component_test.py +++ b/sdk/python/kfp/components/base_component_test.py @@ -93,25 +93,26 @@ def test_instantiate_component_with_positional_arugment(self): with self.assertRaisesRegex( TypeError, 'Components must be instantiated using keyword arguments.' - ' Positional parameters are not allowed \(found 3 such' - ' parameters for component "component_1"\).'): + r' Positional parameters are not allowed \(found 3 such' + r' parameters for component "component_1"\).'): component_op('abc', 1, 2.3) def test_instantiate_component_with_unexpected_keyword_arugment(self): with self.assertRaisesRegex( TypeError, - 'component_1\(\) got an unexpected keyword argument "input0".'): + r'component_1\(\) got an unexpected keyword argument "input0".' + ): component_op(input1='abc', input2=1, input3=2.3, input0='extra') def test_instantiate_component_with_missing_arugments(self): with self.assertRaisesRegex( TypeError, - 'component_1\(\) missing 1 required argument: input1.'): + r'component_1\(\) missing 1 required argument: input1.'): component_op(input2=1) with self.assertRaisesRegex( TypeError, - 'component_1\(\) missing 2 required arguments: input1, input2.' + r'component_1\(\) missing 2 required arguments: input1, input2.' ): component_op() diff --git a/sdk/python/kfp/components/base_model.py b/sdk/python/kfp/components/base_model.py index 042f05b1365..2934f86b296 100644 --- a/sdk/python/kfp/components/base_model.py +++ b/sdk/python/kfp/components/base_model.py @@ -202,33 +202,33 @@ def base_model_format(x: BaseModelType) -> str: CHARS = 0 def first_level_indent(string: str, chars: int = 1) -> str: - return "\n".join(" " * chars + p for p in string.split("\n")) + return '\n'.join(' ' * chars + p for p in string.split('\n')) def body_level_indent(string: str, chars=4) -> str: - a, *b = string.split("\n") - return a + "\n" + first_level_indent( - "\n".join(b), + a, *b = string.split('\n') + return a + '\n' + first_level_indent( + '\n'.join(b), chars=chars, ) if b else a def parts() -> Iterator[str]: if dataclasses.is_dataclass(x): - yield type(x).__name__ + "(" + yield type(x).__name__ + '(' def fields() -> Iterator[str]: for field in dataclasses.fields(x): nindent = CHARS + len(field.name) + 4 value = getattr(x, field.name) rep_value = base_model_format(value) - yield (" " * (CHARS + 3) + body_level_indent( - f"{field.name}={rep_value}", chars=nindent)) + yield (' ' * (CHARS + 3) + body_level_indent( + f'{field.name}={rep_value}', chars=nindent)) - yield ",\n".join(fields()) - yield " " * CHARS + ")" + yield ',\n'.join(fields()) + yield ' ' * CHARS + ')' else: yield pprint.pformat(x) - return "\n".join(parts()) + return '\n'.join(parts()) def convert_object_to_dict(obj: BaseModelType, diff --git a/sdk/python/kfp/components/base_model_test.py b/sdk/python/kfp/components/base_model_test.py index 04b26efb090..aea2b700b69 100644 --- a/sdk/python/kfp/components/base_model_test.py +++ b/sdk/python/kfp/components/base_model_test.py @@ -190,8 +190,8 @@ class MyClass(base_model.BaseModel): z: Dict[str, int] _aliases = {'x': 'a', 'z': 'b'} - res = MyClass(x=1, y=[2], z={"key": 3}).to_dict(by_alias=True) - self.assertEqual(res, {'a': 1, 'y': [2], 'b': {"key": 3}}) + res = MyClass(x=1, y=[2], z={'key': 3}).to_dict(by_alias=True) + self.assertEqual(res, {'a': 1, 'y': [2], 'b': {'key': 3}}) def test_to_dict_by_alias_nested(self): @@ -460,6 +460,3 @@ def test_is_same_as_typing_version(self): if __name__ == '__main__': unittest.main() - -# # TODO: test no subtype -# # TODO: adjust special types to actually use that data structure diff --git a/sdk/python/kfp/components/pipeline_task.py b/sdk/python/kfp/components/pipeline_task.py index c1291b13a8d..63874b0a7e0 100644 --- a/sdk/python/kfp/components/pipeline_task.py +++ b/sdk/python/kfp/components/pipeline_task.py @@ -316,7 +316,7 @@ def expand_command_part(arg) -> Union[str, List[str], None]: return expanded_result else: - raise TypeError('Unrecognized argument type: {}'.format(arg)) + raise TypeError(f'Unrecognized argument type: {arg}') def expand_argument_list(argument_list) -> Optional[List[str]]: if argument_list is None: diff --git a/sdk/python/kfp/components/structures.py b/sdk/python/kfp/components/structures.py index 290d104f978..b1c768d1516 100644 --- a/sdk/python/kfp/components/structures.py +++ b/sdk/python/kfp/components/structures.py @@ -331,7 +331,7 @@ def convert_str_or_dict_to_placeholder( if not has_one_entry: raise ValueError( - f"Got unexpected dictionary {res}. Expected a dictionary with one entry." + f'Got unexpected dictionary {res}. Expected a dictionary with one entry.' ) first_key = list(res.keys())[0] @@ -554,7 +554,7 @@ def convert_v1_if_present_placholder_to_v2( return arg else: raise TypeError( - f"Unexpected argument {arg} of type {type(arg)}.") + f'Unexpected argument {arg} of type {type(arg)}.') implementation = component_dict['implementation']['container'] implementation['command'] = [ diff --git a/sdk/python/kfp/components/structures_test.py b/sdk/python/kfp/components/structures_test.py index 405d3b0b56f..9fc8fa89578 100644 --- a/sdk/python/kfp/components/structures_test.py +++ b/sdk/python/kfp/components/structures_test.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Kubeflow Authors +# Copyright 2021-2022 The Kubeflow Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.