From c063fc688cf20c37ed830de5e3dac4a664fd8241 Mon Sep 17 00:00:00 2001 From: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com> Date: Fri, 25 Mar 2022 11:35:50 -0600 Subject: [PATCH] Update black precommit (#22521) Use latest version of black, drop py36, and add py310. --- .pre-commit-config.yaml | 2 +- .../databricks/hooks/databricks_base.py | 2 +- .../elasticsearch/log/es_task_handler.py | 2 +- .../providers/google/cloud/hooks/mlengine.py | 4 +-- pyproject.toml | 2 +- scripts/in_container/run_resource_check.py | 2 +- .../google/cloud/hooks/test_vision.py | 30 ++++++++----------- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e93abeb063754..0d83a5dbebedd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -144,7 +144,7 @@ repos: - license-templates/LICENSE.txt - --fuzzy-match-generates-todo - repo: https://github.com/psf/black - rev: 21.12b0 + rev: 22.1.0 hooks: - id: black args: [--config=./pyproject.toml] diff --git a/airflow/providers/databricks/hooks/databricks_base.py b/airflow/providers/databricks/hooks/databricks_base.py index f545f26a25408..ec856a053d005 100644 --- a/airflow/providers/databricks/hooks/databricks_base.py +++ b/airflow/providers/databricks/hooks/databricks_base.py @@ -113,7 +113,7 @@ def my_after_func(retry_state): else: self.retry_args = dict( stop=stop_after_attempt(self.retry_limit), - wait=wait_exponential(min=self.retry_delay, max=(2 ** retry_limit)), + wait=wait_exponential(min=self.retry_delay, max=(2**retry_limit)), retry=retry_if_exception(self._retryable_error), after=my_after_func, ) diff --git a/airflow/providers/elasticsearch/log/es_task_handler.py b/airflow/providers/elasticsearch/log/es_task_handler.py index 11304d33392ca..85f8b1f15a456 100644 --- a/airflow/providers/elasticsearch/log/es_task_handler.py +++ b/airflow/providers/elasticsearch/log/es_task_handler.py @@ -286,7 +286,7 @@ def es_read(self, log_id: str, offset: str, metadata: dict) -> list: def emit(self, record): if self.handler: - record.offset = int(time() * (10 ** 9)) + record.offset = int(time() * (10**9)) self.handler.emit(record) def set_context(self, ti: TaskInstance) -> None: diff --git a/airflow/providers/google/cloud/hooks/mlengine.py b/airflow/providers/google/cloud/hooks/mlengine.py index fdff4a0f2cded..b1b6e83918aa4 100644 --- a/airflow/providers/google/cloud/hooks/mlengine.py +++ b/airflow/providers/google/cloud/hooks/mlengine.py @@ -57,13 +57,13 @@ def _poll_with_exponential_delay(request, execute_num_retries, max_n, is_done_fu log.info('Operation is done: %s', response) return response - time.sleep((2 ** i) + (random.randint(0, 1000) / 1000)) + time.sleep((2**i) + (random.randint(0, 1000) / 1000)) except HttpError as e: if e.resp.status != 429: log.info('Something went wrong. Not retrying: %s', format(e)) raise else: - time.sleep((2 ** i) + (random.randint(0, 1000) / 1000)) + time.sleep((2**i) + (random.randint(0, 1000) / 1000)) raise ValueError(f'Connection could not be established after {max_n} retries.') diff --git a/pyproject.toml b/pyproject.toml index 723a5cb66b027..0fb2fed307ca8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,5 +16,5 @@ # under the License. [tool.black] line-length = 110 -target-version = ['py36', 'py37', 'py38', 'py39'] +target-version = ['py37', 'py38', 'py39', 'py310'] skip-string-normalization = true diff --git a/scripts/in_container/run_resource_check.py b/scripts/in_container/run_resource_check.py index 42efe1aacfc9f..bd2a513c7c2be 100644 --- a/scripts/in_container/run_resource_check.py +++ b/scripts/in_container/run_resource_check.py @@ -38,7 +38,7 @@ def get_size(bytes): Convert Bytes into Gigabytes 1 Gigabytes = 1024*1024*1024 = 1073741824 bytes """ - factor = 1024 ** 3 + factor = 1024**3 value_gb = bytes / factor return value_gb diff --git a/tests/providers/google/cloud/hooks/test_vision.py b/tests/providers/google/cloud/hooks/test_vision.py index 433503250f06f..416d8ce4e6c5f 100644 --- a/tests/providers/google/cloud/hooks/test_vision.py +++ b/tests/providers/google/cloud/hooks/test_vision.py @@ -313,15 +313,12 @@ def test_update_productset_explicit_name_different_from_constructed(self, get_co err = ctx.value # self.assertIn("The required parameter 'project_id' is missing", str(err)) assert err - assert ( - ERR_DIFF_NAMES.format( - explicit_name=explicit_ps_name, - constructed_name=template_ps_name, - label="ProductSet", - id_label="productset_id", - ) - in str(err) - ) + assert ERR_DIFF_NAMES.format( + explicit_name=explicit_ps_name, + constructed_name=template_ps_name, + label="ProductSet", + id_label="productset_id", + ) in str(err) update_product_set_method.assert_not_called() @mock.patch('airflow.providers.google.cloud.hooks.vision.CloudVisionHook.get_conn') @@ -652,15 +649,12 @@ def test_update_product_explicit_name_different_from_constructed(self, get_conn) ) err = ctx.value assert err - assert ( - ERR_DIFF_NAMES.format( - explicit_name=explicit_p_name, - constructed_name=template_p_name, - label="Product", - id_label="product_id", - ) - in str(err) - ) + assert ERR_DIFF_NAMES.format( + explicit_name=explicit_p_name, + constructed_name=template_p_name, + label="Product", + id_label="product_id", + ) in str(err) update_product_method.assert_not_called() @mock.patch('airflow.providers.google.cloud.hooks.vision.CloudVisionHook.get_conn')