From 1dafdc00b11cf0c25c9c4b7412162e4068e70365 Mon Sep 17 00:00:00 2001 From: Deepyaman Datta Date: Wed, 22 Sep 2021 11:17:53 -0400 Subject: [PATCH] Use `pyupgrade` to replace format strings and more (#1242) --- .pre-commit-config.yaml | 12 ++- .pylintrc | 2 +- RELEASE.md | 2 +- docs/conf.py | 13 ++-- features/steps/cli_steps.py | 8 +- .../docs/source/conf.py | 1 - .../{{ cookiecutter.repo_name }}/src/setup.py | 2 +- features/steps/util.py | 2 +- kedro/config/default_logger.py | 4 +- kedro/config/templated_config.py | 10 +-- kedro/extras/datasets/api/api_dataset.py | 3 +- kedro/extras/datasets/pandas/sql_dataset.py | 4 +- kedro/extras/datasets/spark/spark_dataset.py | 11 ++- .../datasets/spark/spark_jdbc_dataset.py | 4 +- kedro/framework/cli/pipeline.py | 18 +++-- kedro/framework/cli/starters.py | 2 +- kedro/io/core.py | 30 ++++---- kedro/io/lambda_data_set.py | 6 +- kedro/io/memory_data_set.py | 5 +- kedro/io/partitioned_data_set.py | 17 ++--- kedro/pipeline/decorators.py | 6 +- kedro/pipeline/modular_pipeline.py | 5 +- kedro/pipeline/node.py | 76 ++++++++----------- kedro/pipeline/pipeline.py | 35 ++++----- kedro/runner/parallel_runner.py | 31 ++++---- .../docs/source/conf.py | 1 - .../{{ cookiecutter.repo_name }}/src/setup.py | 2 +- setup.py | 4 +- .../datasets/geojson/test_geojson_dataset.py | 4 +- .../matplotlib/test_matplotlib_writer.py | 4 +- .../networkx/test_networkx_dataset.py | 4 +- .../datasets/pandas/test_csv_dataset.py | 4 +- .../datasets/pandas/test_excel_dataset.py | 4 +- .../datasets/pandas/test_feather_dataset.py | 4 +- .../datasets/pandas/test_hdf_dataset.py | 4 +- .../datasets/pandas/test_json_dataset.py | 4 +- .../datasets/pandas/test_parquet_dataset.py | 4 +- .../datasets/pickle/test_pickle_dataset.py | 4 +- .../datasets/pillow/test_image_dataset.py | 4 +- .../datasets/spark/test_spark_hive_dataset.py | 6 +- .../extras/datasets/text/test_text_dataset.py | 4 +- .../extras/datasets/yaml/test_yaml_dataset.py | 4 +- .../extras/decorators/test_memory_profiler.py | 10 ++- tests/framework/cli/test_cli.py | 2 +- tests/io/test_incremental_dataset.py | 4 +- tests/pipeline/test_decorators.py | 19 ++++- tests/pipeline/test_node.py | 8 +- tests/pipeline/test_pipeline.py | 4 +- tests/runner/test_parallel_runner.py | 4 +- tests/versioning/test_journal.py | 2 +- tools/license_and_headers.py | 2 +- 51 files changed, 211 insertions(+), 218 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ac1e051964..1738bc3d3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,9 +37,15 @@ repos: - repo: https://github.com/asottile/blacken-docs rev: v1.9.2 hooks: - - id: blacken-docs - additional_dependencies: [black==21.5b1] - entry: blacken-docs --skip-errors + - id: blacken-docs + additional_dependencies: [black==21.5b1] + entry: blacken-docs --skip-errors + + - repo: https://github.com/asottile/pyupgrade + rev: v2.26.0 + hooks: + - id: pyupgrade + args: [--py36-plus] - repo: local hooks: diff --git a/.pylintrc b/.pylintrc index bad78ecaac..a6aa8fde01 100644 --- a/.pylintrc +++ b/.pylintrc @@ -50,7 +50,7 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=ungrouped-imports,bad-continuation,duplicate-code,consider-using-f-string +disable=ungrouped-imports,bad-continuation,duplicate-code # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/RELEASE.md b/RELEASE.md index f7e737f8fe..cbe3a7c5c4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -10,6 +10,7 @@ ## Upcoming deprecations for Kedro 0.18.0 ## Thanks for supporting contributions +[Deepyaman Datta](https://github.com/deepyaman) # Release 0.17.5 @@ -28,7 +29,6 @@ | `tracking.MetricsDataSet` | Dataset to track numeric metrics for experiment tracking | `kedro.extras.datasets.tracking` | | `tracking.JSONDataSet` | Dataset to track data for experiment tracking | `kedro.extras.datasets.tracking` | - ## Bug fixes and other changes * Bumped minimum required `fsspec` version to 2021.04. * Fixed the `kedro install` and `kedro build-reqs` flows when uninstalled dependencies are present in a project's `settings.py`, `context.py` or `hooks.py` ([Issue #829](https://github.com/quantumblacklabs/kedro/issues/829)). diff --git a/docs/conf.py b/docs/conf.py index bb59242ac9..e59f55c9e8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # Kedro documentation build configuration file, created by # sphinx-quickstart on Mon Dec 18 11:31:24 2017. @@ -376,7 +375,7 @@ def autolink_replacements(what: str) -> List[Tuple[str, str, str]]: # first do plural only for classes replacements += [ ( - r"``{}``s".format(obj), + fr"``{obj}``s", f":{what}:`~{module}.{obj}`\\\\s", obj, ) @@ -385,7 +384,7 @@ def autolink_replacements(what: str) -> List[Tuple[str, str, str]]: # singular replacements += [ - (r"``{}``".format(obj), f":{what}:`~{module}.{obj}`", obj) + (fr"``{obj}``", f":{what}:`~{module}.{obj}`", obj) for obj in objects ] @@ -395,13 +394,13 @@ def autolink_replacements(what: str) -> List[Tuple[str, str, str]]: if what == "class": # first do plural only for classes suggestions += [ - (r"(? requests.Response: response.raise_for_status() except requests.exceptions.HTTPError as exc: raise DataSetError("Failed to fetch data", exc) from exc - except socket.error as exc: + except OSError as exc: raise DataSetError("Failed to connect to the remote server") from exc return response diff --git a/kedro/extras/datasets/pandas/sql_dataset.py b/kedro/extras/datasets/pandas/sql_dataset.py index 5744fb5b56..06caee3990 100644 --- a/kedro/extras/datasets/pandas/sql_dataset.py +++ b/kedro/extras/datasets/pandas/sql_dataset.py @@ -80,8 +80,8 @@ def _find_known_drivers(module_import_error: ImportError) -> Optional[str]: if KNOWN_PIP_INSTALL.get(missing_module): return ( - "You can also try installing missing driver with\n" - "\npip install {}".format(KNOWN_PIP_INSTALL.get(missing_module)) + f"You can also try installing missing driver with\n" + f"\npip install {KNOWN_PIP_INSTALL.get(missing_module)}" ) return None diff --git a/kedro/extras/datasets/spark/spark_dataset.py b/kedro/extras/datasets/spark/spark_dataset.py index ec951e683c..d01d87b53c 100644 --- a/kedro/extras/datasets/spark/spark_dataset.py +++ b/kedro/extras/datasets/spark/spark_dataset.py @@ -164,11 +164,11 @@ def hdfs_glob(self, pattern: str) -> List[str]: for dpath, _, fnames in self.walk(prefix): if fnmatch(dpath, pattern): matched.add(dpath) - matched |= set( + matched |= { f"{dpath}/{fname}" for fname in fnames if fnmatch(f"{dpath}/{fname}", pattern) - ) + } except HdfsError: # pragma: no cover # HdfsError is raised by `self.walk()` if prefix does not exist in HDFS. # Ignore and return an empty list. @@ -271,10 +271,9 @@ def __init__( # pylint: disable=too-many-arguments elif fs_prefix == "hdfs://" and version: warn( - "HDFS filesystem support for versioned {} is in beta and uses " - "`hdfs.client.InsecureClient`, please use with caution".format( - self.__class__.__name__ - ) + f"HDFS filesystem support for versioned {self.__class__.__name__} is " + f"in beta and uses `hdfs.client.InsecureClient`, please use with " + f"caution" ) # default namenode address diff --git a/kedro/extras/datasets/spark/spark_jdbc_dataset.py b/kedro/extras/datasets/spark/spark_jdbc_dataset.py index 78d956b19e..675c1b8a1a 100644 --- a/kedro/extras/datasets/spark/spark_jdbc_dataset.py +++ b/kedro/extras/datasets/spark/spark_jdbc_dataset.py @@ -141,8 +141,8 @@ def __init__( for cred_key, cred_value in credentials.items(): if cred_value is None: raise DataSetError( - "Credential property `{}` cannot be None. " - "Please provide a value.".format(cred_key) + f"Credential property `{cred_key}` cannot be None. " + f"Please provide a value." ) load_properties = self._load_args.get("properties", {}) diff --git a/kedro/framework/cli/pipeline.py b/kedro/framework/cli/pipeline.py index 1b595000e9..6006f8cf3c 100644 --- a/kedro/framework/cli/pipeline.py +++ b/kedro/framework/cli/pipeline.py @@ -76,10 +76,13 @@ ) """ -PipelineArtifacts = NamedTuple( - "PipelineArtifacts", - [("pipeline_dir", Path), ("pipeline_tests", Path), ("pipeline_conf", Path)], -) + +class PipelineArtifacts(NamedTuple): + """An ordered collection of source_path, tests_path, config_paths""" + + pipeline_dir: Path + pipeline_tests: Path + pipeline_conf: Path def _assert_pkg_name_ok(pkg_name: str): @@ -1109,14 +1112,15 @@ def _append_package_reqs( return sorted_reqs = sorted(str(req) for req in reqs_to_add) + sep = "\n" with open(requirements_in, "a", encoding="utf-8") as file: file.write( f"\n\n# Additional requirements from modular pipeline `{pipeline_name}`:\n" ) - file.write("\n".join(sorted_reqs)) + file.write(sep.join(sorted_reqs)) click.secho( - "Added the following requirements from modular pipeline `{}` to " - "requirements.in:\n{}".format(pipeline_name, "\n".join(sorted_reqs)) + f"Added the following requirements from modular pipeline `{pipeline_name}` to " + f"requirements.in:\n{sep.join(sorted_reqs)}" ) click.secho( "Use `kedro install --build-reqs` to compile and install the updated list of " diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index fe39a5357c..ed7a0c469d 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -198,7 +198,7 @@ def _fetch_config_from_file(config_path: str) -> Dict[str, str]: """ try: - with open(config_path, "r", encoding="utf-8") as config_file: + with open(config_path, encoding="utf-8") as config_file: config = yaml.safe_load(config_file) if KedroCliError.VERBOSE_ERROR: diff --git a/kedro/io/core.py b/kedro/io/core.py index a55e727319..814712b53f 100644 --- a/kedro/io/core.py +++ b/kedro/io/core.py @@ -213,8 +213,8 @@ def load(self) -> Any: except Exception as exc: # This exception handling is by design as the composed data sets # can throw any type of exception. - message = "Failed while loading data from data set {}.\n{}".format( - str(self), str(exc) + message = ( + f"Failed while loading data from data set {str(self)}.\n{str(exc)}" ) raise DataSetError(message) from exc @@ -274,22 +274,22 @@ def _to_str(obj, is_root=False): @abc.abstractmethod def _load(self) -> Any: raise NotImplementedError( - "`{}` is a subclass of AbstractDataSet and" - "it must implement the `_load` method".format(self.__class__.__name__) + f"`{self.__class__.__name__}` is a subclass of AbstractDataSet and " + f"it must implement the `_load` method" ) @abc.abstractmethod def _save(self, data: Any) -> None: raise NotImplementedError( - "`{}` is a subclass of AbstractDataSet and" - "it must implement the `_save` method".format(self.__class__.__name__) + f"`{self.__class__.__name__}` is a subclass of AbstractDataSet and " + f"it must implement the `_save` method" ) @abc.abstractmethod def _describe(self) -> Dict[str, Any]: raise NotImplementedError( - "`{}` is a subclass of AbstractDataSet and" - "it must implement the `_describe` method".format(self.__class__.__name__) + f"`{self.__class__.__name__}` is a subclass of AbstractDataSet and " + f"it must implement the `_describe` method" ) def exists(self) -> bool: @@ -307,8 +307,8 @@ def exists(self) -> bool: self._logger.debug("Checking whether target of %s exists", str(self)) return self._exists() except Exception as exc: - message = "Failed during exists check for data set {}.\n{}".format( - str(self), str(exc) + message = ( + f"Failed during exists check for data set {str(self)}.\n{str(exc)}" ) raise DataSetError(message) from exc @@ -605,8 +605,8 @@ def _get_save_path(self) -> PurePosixPath: if self._exists_function(str(versioned_path)): raise DataSetError( - "Save path `{}` for {} must not exist if versioning " - "is enabled.".format(versioned_path, str(self)) + f"Save path `{versioned_path}` for {str(self)} must not exist if " + f"versioning is enabled." ) return versioned_path @@ -661,8 +661,8 @@ def exists(self) -> bool: except VersionNotFoundError: return False except Exception as exc: # SKIP_IF_NO_SPARK - message = "Failed during exists check for data set {}.\n{}".format( - str(self), str(exc) + message = ( + f"Failed during exists check for data set {str(self)}.\n{str(exc)}" ) raise DataSetError(message) from exc @@ -696,7 +696,7 @@ def _parse_filepath(filepath: str) -> Dict[str, str]: if protocol == "file": windows_path = re.match(r"^/([a-zA-Z])[:|]([\\/].*)$", path) if windows_path: - path = "{}:{}".format(*windows_path.groups()) + path = ":".join(windows_path.groups()) options = {"protocol": protocol, "path": path} diff --git a/kedro/io/lambda_data_set.py b/kedro/io/lambda_data_set.py index 2dd1977f94..c2f5df0402 100644 --- a/kedro/io/lambda_data_set.py +++ b/kedro/io/lambda_data_set.py @@ -130,10 +130,8 @@ def __init__( ]: if value is not None and not callable(value): raise DataSetError( - "`{}` function for LambdaDataSet must be a Callable. " - "Object of type `{}` provided instead.".format( - name, value.__class__.__name__ - ) + f"`{name}` function for LambdaDataSet must be a Callable. " + f"Object of type `{value.__class__.__name__}` provided instead." ) self.__load = load diff --git a/kedro/io/memory_data_set.py b/kedro/io/memory_data_set.py index 27f9defe03..43e4f494d2 100644 --- a/kedro/io/memory_data_set.py +++ b/kedro/io/memory_data_set.py @@ -153,9 +153,8 @@ def _copy_with_mode(data: Any, copy_mode: str) -> Any: copied_data = data else: raise DataSetError( - "Invalid copy mode: {}. Possible values are: deepcopy, copy, assign.".format( - copy_mode - ) + f"Invalid copy mode: {copy_mode}. " + f"Possible values are: deepcopy, copy, assign." ) return copied_data diff --git a/kedro/io/partitioned_data_set.py b/kedro/io/partitioned_data_set.py index d5a3ee1a42..abde60607e 100644 --- a/kedro/io/partitioned_data_set.py +++ b/kedro/io/partitioned_data_set.py @@ -160,10 +160,9 @@ def __init__( # pylint: disable=too-many-arguments self._dataset_type, self._dataset_config = parse_dataset_definition(dataset) if VERSION_KEY in self._dataset_config: raise DataSetError( - "`{}` does not support versioning of the underlying dataset. " - "Please remove `{}` flag from the dataset definition.".format( - self.__class__.__name__, VERSIONED_FLAG_KEY - ) + f"`{self.__class__.__name__}` does not support versioning of the " + f"underlying dataset. Please remove `{VERSIONED_FLAG_KEY}` flag from " + f"the dataset definition." ) if credentials: @@ -190,8 +189,8 @@ def __init__( # pylint: disable=too-many-arguments self._filepath_arg = filepath_arg if self._filepath_arg in self._dataset_config: warn( - "`{}` key must not be specified in the dataset definition as it " - "will be overwritten by partition path".format(self._filepath_arg) + f"`{self._filepath_arg}` key must not be specified in the dataset " + f"definition as it will be overwritten by partition path" ) self._load_args = deepcopy(load_args) or {} @@ -422,10 +421,8 @@ def _parse_checkpoint_config( for key in {VERSION_KEY, VERSIONED_FLAG_KEY} & checkpoint_config.keys(): raise DataSetError( - "`{}` does not support versioning of the checkpoint. " - "Please remove `{}` key from the checkpoint definition.".format( - self.__class__.__name__, key - ) + f"`{self.__class__.__name__}` does not support versioning of the " + f"checkpoint. Please remove `{key}` key from the checkpoint definition." ) default_checkpoint_path = self._sep.join( diff --git a/kedro/pipeline/decorators.py b/kedro/pipeline/decorators.py index 9f994468c6..893105ebc7 100644 --- a/kedro/pipeline/decorators.py +++ b/kedro/pipeline/decorators.py @@ -40,14 +40,14 @@ def _func_full_name(func: Callable): return f"{func.__module__}.{func.__qualname__}" -def _human_readable_time(elapsed: float): # pragma: no cover +def _human_readable_time(elapsed: float): mins, secs = divmod(elapsed, 60) hours, mins = divmod(mins, 60) if hours > 0: - message = "%dh%02dm%02ds" % (hours, mins, secs) + message = f"{int(hours)}h{int(mins):02}m{int(secs):02}s" elif mins > 0: - message = "%dm%02ds" % (mins, secs) + message = f"{int(mins)}m{int(secs):02}s" elif secs >= 1: message = f"{secs:.2f}s" else: diff --git a/kedro/pipeline/modular_pipeline.py b/kedro/pipeline/modular_pipeline.py index 2caed7678d..8abf28abf9 100644 --- a/kedro/pipeline/modular_pipeline.py +++ b/kedro/pipeline/modular_pipeline.py @@ -90,9 +90,8 @@ def _validate_datasets_exist( non_existent = (inputs | outputs | parameters) - existing if non_existent: raise ModularPipelineError( - "Failed to map datasets and/or parameters: {}".format( - ", ".join(sorted(non_existent)) - ) + f"Failed to map datasets and/or parameters: " + f"{', '.join(sorted(non_existent))}" ) diff --git a/kedro/pipeline/node.py b/kedro/pipeline/node.py index 770cdd1c4f..38a6027f20 100644 --- a/kedro/pipeline/node.py +++ b/kedro/pipeline/node.py @@ -197,8 +197,9 @@ def _sorted_set_to_str(xset): return prefix + f"{self._func_name}({in_str}) -> {out_str}" def __repr__(self): # pragma: no cover - return "Node({}, {!r}, {!r}, {!r})".format( - self._func_name, self._inputs, self._outputs, self._name + return ( + f"Node({self._func_name}, {repr(self._inputs)}, {repr(self._outputs)}, " + f"{repr(self._name)})" ) def __call__(self, **kwargs) -> Dict[str, Any]: @@ -468,10 +469,9 @@ def run(self, inputs: Dict[str, Any] = None) -> Dict[str, Any]: def _run_with_no_inputs(self, inputs: Dict[str, Any]): if inputs: raise ValueError( - "Node {} expected no inputs, " - "but got the following {} input(s) instead: {}".format( - str(self), len(inputs), list(sorted(inputs.keys())) - ) + f"Node {str(self)} expected no inputs, " + f"but got the following {len(inputs)} input(s) instead: " + f"{sorted(inputs.keys())}." ) return self._decorated_func() @@ -479,10 +479,9 @@ def _run_with_no_inputs(self, inputs: Dict[str, Any]): def _run_with_one_input(self, inputs: Dict[str, Any], node_input: str): if len(inputs) != 1 or node_input not in inputs: raise ValueError( - "Node {} expected one input named '{}', " - "but got the following {} input(s) instead: {}".format( - str(self), node_input, len(inputs), list(sorted(inputs.keys())) - ) + f"Node {str(self)} expected one input named '{node_input}', " + f"but got the following {len(inputs)} input(s) instead: " + f"{sorted(inputs.keys())}." ) return self._decorated_func(inputs[node_input]) @@ -491,30 +490,21 @@ def _run_with_list(self, inputs: Dict[str, Any], node_inputs: List[str]): # Node inputs and provided run inputs should completely overlap if set(node_inputs) != set(inputs.keys()): raise ValueError( - "Node {} expected {} input(s) {}, " - "but got the following {} input(s) instead: {}.".format( - str(self), - len(node_inputs), - node_inputs, - len(inputs), - list(sorted(inputs.keys())), - ) + f"Node {str(self)} expected {len(node_inputs)} input(s) {node_inputs}, " + f"but got the following {len(inputs)} input(s) instead: " + f"{sorted(inputs.keys())}." ) # Ensure the function gets the inputs in the correct order - return self._decorated_func(*[inputs[item] for item in node_inputs]) + return self._decorated_func(*(inputs[item] for item in node_inputs)) def _run_with_dict(self, inputs: Dict[str, Any], node_inputs: Dict[str, str]): # Node inputs and provided run inputs should completely overlap if set(node_inputs.values()) != set(inputs.keys()): raise ValueError( - "Node {} expected {} input(s) {}, " - "but got the following {} input(s) instead: {}.".format( - str(self), - len(set(node_inputs.values())), - list(sorted(set(node_inputs.values()))), - len(inputs), - list(sorted(inputs.keys())), - ) + f"Node {str(self)} expected {len(set(node_inputs.values()))} input(s) " + f"{sorted(set(node_inputs.values()))}, " + f"but got the following {len(inputs)} input(s) instead: " + f"{sorted(inputs.keys())}." ) kwargs = {arg: inputs[alias] for arg, alias in node_inputs.items()} return self._decorated_func(**kwargs) @@ -523,30 +513,26 @@ def _outputs_to_dictionary(self, outputs): def _from_dict(): if set(self._outputs.keys()) != set(outputs.keys()): raise ValueError( - "Failed to save outputs of node {}.\n" - "The node's output keys {} do not " - "match with the returned output's keys {}.".format( - str(self), set(outputs.keys()), set(self._outputs.keys()) - ) + f"Failed to save outputs of node {str(self)}.\n" + f"The node's output keys {set(outputs.keys())} do not match with " + f"the returned output's keys {set(self._outputs.keys())}." ) return {name: outputs[key] for key, name in self._outputs.items()} def _from_list(): if not isinstance(outputs, (list, tuple)): raise ValueError( - "Failed to save outputs of node {}.\n" - "The node definition contains a list of " - "outputs {}, whereas the node function " - "returned a `{}`.".format( - str(self), self._outputs, type(outputs).__name__ - ) + f"Failed to save outputs of node {str(self)}.\n" + f"The node definition contains a list of " + f"outputs {self._outputs}, whereas the node function " + f"returned a `{type(outputs).__name__}`." ) if len(outputs) != len(self._outputs): raise ValueError( - "Failed to save outputs of node {}.\n" - "The node function returned {} output(s), " - "whereas the node definition contains {} " - "output(s).".format(str(self), len(outputs), len(self._outputs)) + f"Failed to save outputs of node {str(self)}.\n" + f"The node function returned {len(outputs)} output(s), " + f"whereas the node definition contains {len(self._outputs)} " + f"output(s)." ) return dict(zip(self._outputs, outputs)) @@ -618,9 +604,9 @@ def _process_inputs_for_bind(inputs: Union[None, str, List[str], Dict[str, str]] def _node_error_message(msg) -> str: return ( - "Invalid Node definition: {}\n" - "Format should be: node(function, inputs, outputs)" - ).format(msg) + f"Invalid Node definition: {msg}\n" + f"Format should be: node(function, inputs, outputs)" + ) def node( diff --git a/kedro/pipeline/pipeline.py b/kedro/pipeline/pipeline.py index b5d6d69ea5..d06b33d99e 100644 --- a/kedro/pipeline/pipeline.py +++ b/kedro/pipeline/pipeline.py @@ -60,9 +60,8 @@ def _transcode_split(element: str) -> Tuple[str, str]: if len(split_name) > 2: raise ValueError( - "Expected maximum 1 transcoding separator, found {} instead: '{}'.".format( - len(split_name) - 1, element - ) + f"Expected maximum 1 transcoding separator, found {len(split_name) - 1} " + f"instead: '{element}'." ) if len(split_name) == 1: split_name.append("") @@ -200,9 +199,8 @@ def __repr__(self): # pragma: no cover nodes_reprs = [repr(node) for node in self.nodes[:max_nodes_to_display]] if len(self.nodes) > max_nodes_to_display: nodes_reprs.append("...") - nodes_reprs_str = ( - "[\n{}\n]".format(",\n".join(nodes_reprs)) if nodes_reprs else "[]" - ) + sep = ",\n" + nodes_reprs_str = f"[\n{sep.join(nodes_reprs)}\n]" if nodes_reprs else "[]" constructor_repr = f"({nodes_reprs_str})" return f"{self.__class__.__name__}{constructor_repr}" @@ -233,7 +231,7 @@ def all_inputs(self) -> Set[str]: All node input names as a Set. """ - return set.union(set(), *[node.inputs for node in self.nodes]) + return set.union(set(), *(node.inputs for node in self.nodes)) def all_outputs(self) -> Set[str]: """All outputs of all nodes in the pipeline. @@ -242,7 +240,7 @@ def all_outputs(self) -> Set[str]: All node outputs. """ - return set.union(set(), *[node.outputs for node in self.nodes]) + return set.union(set(), *(node.outputs for node in self.nodes)) def _remove_intermediates(self, datasets: Set[str]) -> Set[str]: intermediate = {_strip_transcoding(i) for i in self.all_inputs()} & { @@ -433,9 +431,8 @@ def only_nodes_with_namespace(self, node_namespace: str) -> "Pipeline": ] if not nodes: raise ValueError( - "Pipeline does not contain nodes with namespace(s) {}.".format( - list(node_namespace) - ) + f"Pipeline does not contain nodes with namespace(s) " + f"{list(node_namespace)}." ) return Pipeline(nodes) @@ -785,8 +782,8 @@ def _validate_unique_outputs(nodes: List[Node]) -> None: duplicates = [key for key, value in Counter(outputs).items() if value > 1] if duplicates: raise OutputNotUniqueError( - "Output(s) {} are returned by more than one nodes. Node " - "outputs must be unique.".format(sorted(duplicates)) + f"Output(s) {sorted(duplicates)} are returned by more than one nodes. Node " + f"outputs must be unique." ) @@ -796,8 +793,8 @@ def _validate_unique_confirms(nodes: List[Node]) -> None: duplicates = [key for key, value in Counter(confirms).items() if value > 1] if duplicates: raise ConfirmNotUniqueError( - "{} datasets are confirmed by more than one node. Node " - "confirms must be unique.".format(sorted(duplicates)) + f"{sorted(duplicates)} datasets are confirmed by more than one node. Node " + f"confirms must be unique." ) @@ -820,10 +817,10 @@ def _validate_transcoded_inputs_outputs(nodes: List[Node]) -> None: if invalid: raise ValueError( - "The following datasets are used with transcoding, but " - "were referenced without the separator: {}.\n" - "Please specify a transcoding option or " - "rename the datasets.".format(", ".join(invalid)) + f"The following datasets are used with transcoding, but " + f"were referenced without the separator: {', '.join(invalid)}.\n" + f"Please specify a transcoding option or " + f"rename the datasets." ) diff --git a/kedro/runner/parallel_runner.py b/kedro/runner/parallel_runner.py index 3758881e26..cad3a7a0ef 100644 --- a/kedro/runner/parallel_runner.py +++ b/kedro/runner/parallel_runner.py @@ -210,12 +210,12 @@ def _validate_nodes(cls, nodes: Iterable[Node]): if unserializable: raise AttributeError( - "The following nodes cannot be serialized: {}\nIn order to " - "utilize multiprocessing you need to make sure all nodes are " - "serializable, i.e. nodes should not include lambda " - "functions, nested functions, closures, etc.\nIf you " - "are using custom decorators ensure they are correctly using " - "functools.wraps().".format(sorted(unserializable)) + f"The following nodes cannot be serialized: {sorted(unserializable)}\n" + f"In order to utilize multiprocessing you need to make sure all nodes " + f"are serializable, i.e. nodes should not include lambda " + f"functions, nested functions, closures, etc.\nIf you " + f"are using custom decorators ensure they are correctly using " + f"functools.wraps()." ) @classmethod @@ -239,12 +239,12 @@ def _validate_catalog(cls, catalog: DataCatalog, pipeline: Pipeline): if unserializable: raise AttributeError( - "The following data sets cannot be used with multiprocessing: " - "{}\nIn order to utilize multiprocessing you need to make sure " - "all data sets are serializable, i.e. data sets should not make " - "use of lambda functions, nested functions, closures etc.\nIf you " - "are using custom decorators ensure they are correctly using " - "functools.wraps().".format(sorted(unserializable)) + f"The following data sets cannot be used with multiprocessing: " + f"{sorted(unserializable)}\nIn order to utilize multiprocessing you " + f"need to make sure all data sets are serializable, i.e. data sets " + f"should not make use of lambda functions, nested functions, closures " + f"etc.\nIf you are using custom decorators ensure they are correctly " + f"using functools.wraps()." ) memory_data_sets = [] @@ -258,9 +258,10 @@ def _validate_catalog(cls, catalog: DataCatalog, pipeline: Pipeline): if memory_data_sets: raise AttributeError( - "The following data sets are memory data sets: {}\n" - "ParallelRunner does not support output to externally created " - "MemoryDataSets".format(sorted(memory_data_sets)) + f"The following data sets are memory data sets: " + f"{sorted(memory_data_sets)}\n" + f"ParallelRunner does not support output to externally created " + f"MemoryDataSets" ) def _get_required_workers_count(self, pipeline: Pipeline): diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/docs/source/conf.py b/kedro/templates/project/{{ cookiecutter.repo_name }}/docs/source/conf.py index e9be509eea..15a0a93289 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/docs/source/conf.py +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/docs/source/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # Copyright 2021 QuantumBlack Visual Analytics Limited # diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/src/setup.py b/kedro/templates/project/{{ cookiecutter.repo_name }}/src/setup.py index 940262245b..c68159befa 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/src/setup.py +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/src/setup.py @@ -34,7 +34,7 @@ # get the dependencies and installs -with open("requirements.txt", "r", encoding="utf-8") as f: +with open("requirements.txt", encoding="utf-8") as f: # Make sure we strip all comments and options (e.g "--extra-index-url") # that arise from a modified pip.conf file that configure global options # when running kedro build-reqs diff --git a/setup.py b/setup.py index d874528429..b2c3d23802 100644 --- a/setup.py +++ b/setup.py @@ -53,11 +53,11 @@ version = result.group(1) # get the dependencies and installs -with open("requirements.txt", "r", encoding="utf-8") as f: +with open("requirements.txt", encoding="utf-8") as f: requires = [x.strip() for x in f if x.strip()] # get test dependencies and installs -with open("test_requirements.txt", "r", encoding="utf-8") as f: +with open("test_requirements.txt", encoding="utf-8") as f: test_requires = [x.strip() for x in f if x.strip() and not x.startswith("-r")] diff --git a/tests/extras/datasets/geojson/test_geojson_dataset.py b/tests/extras/datasets/geojson/test_geojson_dataset.py index 83f6df96e4..c046cbc1eb 100644 --- a/tests/extras/datasets/geojson/test_geojson_dataset.py +++ b/tests/extras/datasets/geojson/test_geojson_dataset.py @@ -224,8 +224,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for GeoJSONDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for GeoJSONDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_geojson_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/matplotlib/test_matplotlib_writer.py b/tests/extras/datasets/matplotlib/test_matplotlib_writer.py index aae1155802..3a8de658f1 100644 --- a/tests/extras/datasets/matplotlib/test_matplotlib_writer.py +++ b/tests/extras/datasets/matplotlib/test_matplotlib_writer.py @@ -297,8 +297,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for MatplotlibWriter\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for MatplotlibWriter\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_plot_writer.save(mock_single_plot) diff --git a/tests/extras/datasets/networkx/test_networkx_dataset.py b/tests/extras/datasets/networkx/test_networkx_dataset.py index bd55f40f5e..f43c90abba 100644 --- a/tests/extras/datasets/networkx/test_networkx_dataset.py +++ b/tests/extras/datasets/networkx/test_networkx_dataset.py @@ -212,8 +212,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for NetworkXDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for NetworkXDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_networkx_data_set.save(dummy_graph_data) diff --git a/tests/extras/datasets/pandas/test_csv_dataset.py b/tests/extras/datasets/pandas/test_csv_dataset.py index 7396fd8d42..1f92fb1499 100644 --- a/tests/extras/datasets/pandas/test_csv_dataset.py +++ b/tests/extras/datasets/pandas/test_csv_dataset.py @@ -285,8 +285,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for CSVDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for CSVDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_csv_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/pandas/test_excel_dataset.py b/tests/extras/datasets/pandas/test_excel_dataset.py index 1ef10d8bf6..530f5eb424 100644 --- a/tests/extras/datasets/pandas/test_excel_dataset.py +++ b/tests/extras/datasets/pandas/test_excel_dataset.py @@ -211,8 +211,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for ExcelDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for ExcelDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_excel_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/pandas/test_feather_dataset.py b/tests/extras/datasets/pandas/test_feather_dataset.py index 46266b742a..9cab5b1f6e 100644 --- a/tests/extras/datasets/pandas/test_feather_dataset.py +++ b/tests/extras/datasets/pandas/test_feather_dataset.py @@ -193,8 +193,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for FeatherDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for FeatherDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_feather_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/pandas/test_hdf_dataset.py b/tests/extras/datasets/pandas/test_hdf_dataset.py index 2d7b178145..a04f0bac3a 100644 --- a/tests/extras/datasets/pandas/test_hdf_dataset.py +++ b/tests/extras/datasets/pandas/test_hdf_dataset.py @@ -233,8 +233,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for HDFDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for HDFDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_hdf_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/pandas/test_json_dataset.py b/tests/extras/datasets/pandas/test_json_dataset.py index f8add6fddc..0a732551c4 100644 --- a/tests/extras/datasets/pandas/test_json_dataset.py +++ b/tests/extras/datasets/pandas/test_json_dataset.py @@ -210,8 +210,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for JSONDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for JSONDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_json_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/pandas/test_parquet_dataset.py b/tests/extras/datasets/pandas/test_parquet_dataset.py index 68c9ff8d7f..42aaa5b6d0 100644 --- a/tests/extras/datasets/pandas/test_parquet_dataset.py +++ b/tests/extras/datasets/pandas/test_parquet_dataset.py @@ -323,8 +323,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for ParquetDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for ParquetDataSet\(.+\)" ) mocker.patch( "pyarrow.fs._ensure_filesystem", diff --git a/tests/extras/datasets/pickle/test_pickle_dataset.py b/tests/extras/datasets/pickle/test_pickle_dataset.py index a8ab3aaa4a..e58d5d231c 100644 --- a/tests/extras/datasets/pickle/test_pickle_dataset.py +++ b/tests/extras/datasets/pickle/test_pickle_dataset.py @@ -242,8 +242,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for PickleDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for PickleDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_pickle_data_set.save(dummy_dataframe) diff --git a/tests/extras/datasets/pillow/test_image_dataset.py b/tests/extras/datasets/pillow/test_image_dataset.py index daaf0af3f0..f0f23e2d92 100644 --- a/tests/extras/datasets/pillow/test_image_dataset.py +++ b/tests/extras/datasets/pillow/test_image_dataset.py @@ -224,8 +224,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for ImageDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for ImageDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_image_dataset.save(image_object) diff --git a/tests/extras/datasets/spark/test_spark_hive_dataset.py b/tests/extras/datasets/spark/test_spark_hive_dataset.py index e6adb49754..3333aaf2e1 100644 --- a/tests/extras/datasets/spark/test_spark_hive_dataset.py +++ b/tests/extras/datasets/spark/test_spark_hive_dataset.py @@ -58,9 +58,9 @@ def spark_hive_session(replace_spark_default_getorcreate): ) .config( "javax.jdo.option.ConnectionURL", - "jdbc:derby:;databaseName={metastore_db_path};create=true".format( - metastore_db_path=(Path(tmpdir) / "warehouse_db").absolute() - ), + f"jdbc:derby:;" + f"databaseName={(Path(tmpdir) / 'warehouse_db').absolute()};" + f"create=true", ) .enableHiveSupport() .getOrCreate() diff --git a/tests/extras/datasets/text/test_text_dataset.py b/tests/extras/datasets/text/test_text_dataset.py index 3697260c35..d159e99f38 100644 --- a/tests/extras/datasets/text/test_text_dataset.py +++ b/tests/extras/datasets/text/test_text_dataset.py @@ -178,8 +178,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for TextDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for TextDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_txt_data_set.save(STRING) diff --git a/tests/extras/datasets/yaml/test_yaml_dataset.py b/tests/extras/datasets/yaml/test_yaml_dataset.py index 1aed709757..57cb419b87 100644 --- a/tests/extras/datasets/yaml/test_yaml_dataset.py +++ b/tests/extras/datasets/yaml/test_yaml_dataset.py @@ -203,8 +203,8 @@ def test_save_version_warning( """Check the warning when saving to the path that differs from the subsequent load path.""" pattern = ( - r"Save version `{0}` did not match load version `{1}` " - r"for YAMLDataSet\(.+\)".format(save_version, load_version) + fr"Save version `{save_version}` did not match load version " + fr"`{load_version}` for YAMLDataSet\(.+\)" ) with pytest.warns(UserWarning, match=pattern): versioned_yaml_data_set.save(dummy_data) diff --git a/tests/extras/decorators/test_memory_profiler.py b/tests/extras/decorators/test_memory_profiler.py index 04a30fc735..bf07ee4466 100644 --- a/tests/extras/decorators/test_memory_profiler.py +++ b/tests/extras/decorators/test_memory_profiler.py @@ -48,8 +48,9 @@ def test_mem_profile(caplog): assert res == 1 assert logger_name == "kedro.extras.decorators.memory_profiler" assert severity == logging.INFO - expected = "Running '{}.{}' consumed".format( - sleeping_identity.__module__, sleeping_identity.__qualname__ + expected = ( + f"Running '{sleeping_identity.__module__}.{sleeping_identity.__qualname__}' " + f"consumed" ) assert expected in message @@ -66,8 +67,9 @@ def test_mem_profile_old_versions(caplog, mocker): assert res == 1 assert logger_name == "kedro.extras.decorators.memory_profiler" assert severity == logging.INFO - expected = "Running '{}.{}' consumed".format( - sleeping_identity.__module__, sleeping_identity.__qualname__ + expected = ( + f"Running '{sleeping_identity.__module__}.{sleeping_identity.__qualname__}' " + f"consumed" ) assert expected in message diff --git a/tests/framework/cli/test_cli.py b/tests/framework/cli/test_cli.py index 2bef56f0be..bf1f381a64 100644 --- a/tests/framework/cli/test_cli.py +++ b/tests/framework/cli/test_cli.py @@ -29,11 +29,11 @@ from itertools import cycle from os.path import join from pathlib import Path +from unittest.mock import patch import anyconfig import click from click.testing import CliRunner -from mock import patch from pytest import fixture, mark, raises from kedro import __version__ as version diff --git a/tests/io/test_incremental_dataset.py b/tests/io/test_incremental_dataset.py index 83d1d4ad6c..6a5dcfc33d 100644 --- a/tests/io/test_incremental_dataset.py +++ b/tests/io/test_incremental_dataset.py @@ -499,8 +499,8 @@ def test_force_checkpoint_checkpoint_file_exists( in S3 if the checkpoint file exists""" # create checkpoint and assert that it exists IncrementalDataSet(mocked_csvs_in_s3, DATASET).confirm() - checkpoint_path = "{}/{}".format( - mocked_csvs_in_s3, IncrementalDataSet.DEFAULT_CHECKPOINT_FILENAME + checkpoint_path = ( + f"{mocked_csvs_in_s3}/{IncrementalDataSet.DEFAULT_CHECKPOINT_FILENAME}" ) checkpoint_value = TextDataSet(checkpoint_path).load() assert checkpoint_value == "p04/data.csv" diff --git a/tests/pipeline/test_decorators.py b/tests/pipeline/test_decorators.py index 6b6f89c30c..86ae5c5a95 100644 --- a/tests/pipeline/test_decorators.py +++ b/tests/pipeline/test_decorators.py @@ -30,9 +30,11 @@ from functools import partial from time import sleep +import pytest + from kedro.io import DataCatalog from kedro.pipeline import Pipeline, node -from kedro.pipeline.decorators import log_time +from kedro.pipeline.decorators import _human_readable_time, log_time from kedro.runner import SequentialRunner @@ -45,6 +47,15 @@ def identity(arg): return arg +@pytest.mark.parametrize( + "elapsed,expected", + [(3600.1, "1h00m00s"), (3599.0, "59m59s"), (59, "59.00s"), (0.1, "100ms")], +) +def test_human_readable_time(elapsed, expected): + message = _human_readable_time(elapsed) + assert message == expected + + def test_log_time(caplog): caplog.clear() func = log_time(sleeping_identity) @@ -54,9 +65,9 @@ def test_log_time(caplog): assert res == 1 assert logger_name == "kedro.pipeline.decorators" assert severity == logging.INFO - expected = "Running '%s.%s' took" % ( - sleeping_identity.__module__, - sleeping_identity.__qualname__, + expected = ( + f"Running '{sleeping_identity.__module__}.{sleeping_identity.__qualname__}' " + f"took" ) assert expected in message diff --git a/tests/pipeline/test_node.py b/tests/pipeline/test_node.py index 00a333ab74..f8d7a535eb 100644 --- a/tests/pipeline/test_node.py +++ b/tests/pipeline/test_node.py @@ -374,7 +374,7 @@ def test_bad_input(func, expected): def apply_f(func: Callable) -> Callable: @wraps(func) def with_f(*args, **kwargs): - return func(*[f"f({a})" for a in args], **kwargs) + return func(*(f"f({a})" for a in args), **kwargs) return with_f @@ -382,7 +382,7 @@ def with_f(*args, **kwargs): def apply_g(func: Callable) -> Callable: @wraps(func) def with_g(*args, **kwargs): - return func(*[f"g({a})" for a in args], **kwargs) + return func(*(f"g({a})" for a in args), **kwargs) return with_g @@ -390,7 +390,7 @@ def with_g(*args, **kwargs): def apply_h(func: Callable) -> Callable: @wraps(func) def with_h(*args, **kwargs): - return func(*[f"h({a})" for a in args], **kwargs) + return func(*(f"h({a})" for a in args), **kwargs) return with_h @@ -398,7 +398,7 @@ def with_h(*args, **kwargs): def apply_ij(func: Callable) -> Callable: @wraps(func) def with_ij(*args, **kwargs): - return func(*[f"ij({a})" for a in args], **kwargs) + return func(*(f"ij({a})" for a in args), **kwargs) return with_ij diff --git a/tests/pipeline/test_pipeline.py b/tests/pipeline/test_pipeline.py index cfff8e0cf3..02527ee3e1 100644 --- a/tests/pipeline/test_pipeline.py +++ b/tests/pipeline/test_pipeline.py @@ -776,7 +776,7 @@ def test_full(self, str_node_inputs_list): def apply_f(func: Callable) -> Callable: @wraps(func) def with_f(*args, **kwargs): - return func(*[f"f({a})" for a in args], **kwargs) + return func(*(f"f({a})" for a in args), **kwargs) return with_f @@ -784,7 +784,7 @@ def with_f(*args, **kwargs): def apply_g(func: Callable) -> Callable: @wraps(func) def with_g(*args, **kwargs): - return func(*[f"g({a})" for a in args], **kwargs) + return func(*(f"g({a})" for a in args), **kwargs) return with_g diff --git a/tests/runner/test_parallel_runner.py b/tests/runner/test_parallel_runner.py index 75b225f2d2..f2892b3bba 100644 --- a/tests/runner/test_parallel_runner.py +++ b/tests/runner/test_parallel_runner.py @@ -254,8 +254,8 @@ def test_memory_dataset_not_serializable(self, is_async, catalog): pipeline = Pipeline([node(return_not_serializable, "A", "B")]) catalog.add_feed_dict(feed_dict=dict(A=42)) pattern = ( - r"{0} cannot be serialized. ParallelRunner implicit memory datasets " - r"can only be used with serializable data".format(str(data.__class__)) + fr"{str(data.__class__)} cannot be serialized. ParallelRunner implicit " + fr"memory datasets can only be used with serializable data" ) with pytest.raises(DataSetError, match=pattern): diff --git a/tests/versioning/test_journal.py b/tests/versioning/test_journal.py index 5af9c8113f..4da2f2a5d9 100644 --- a/tests/versioning/test_journal.py +++ b/tests/versioning/test_journal.py @@ -117,7 +117,7 @@ def test_deprecation_warning(self, tmp_path): def test_git_sha(tmp_path, mocker): - mocker.patch("subprocess.check_output", return_value="mocked_return".encode()) + mocker.patch("subprocess.check_output", return_value=b"mocked_return") result = _git_sha(tmp_path) assert result == "mocked_return" diff --git a/tools/license_and_headers.py b/tools/license_and_headers.py index c16d319d2f..1e4e583cb9 100644 --- a/tools/license_and_headers.py +++ b/tools/license_and_headers.py @@ -44,7 +44,7 @@ def files_at_path(path: str): def files_missing_substring(file_names, substring): for file_name in file_names: - with open(file_name, "r", encoding="utf-8") as current_file: + with open(file_name, encoding="utf-8") as current_file: content = current_file.read() if content.strip() and substring not in content: