Skip to content

Commit 8c42cf1

Browse files
authored
Use PyUpgrade to use Python 3.6 features (#11447)
Use features like `f-strings` instead of format across the code-base. More details: https://github.com/asottile/pyupgrade
1 parent 8000ab7 commit 8c42cf1

File tree

323 files changed

+1046
-1099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+1046
-1099
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ repos:
177177
- id: fix-encoding-pragma
178178
args:
179179
- --remove
180+
- repo: https://github.com/asottile/pyupgrade
181+
rev: v2.7.3
182+
hooks:
183+
- id: pyupgrade
184+
args: ["--py36-plus"]
180185
- repo: https://github.com/pre-commit/pygrep-hooks
181186
rev: v1.6.0
182187
hooks:

BREEZE.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,8 +2005,8 @@ This is the current syntax for `./breeze <./breeze>`_:
20052005
helm-lint incorrect-use-of-LoggingMixin insert-license isort language-matters
20062006
lint-dockerfile lint-openapi mermaid mixed-line-ending mypy mypy-helm
20072007
no-relative-imports pre-commit-descriptions provide-create-sessions pydevd
2008-
pydocstyle pylint pylint-tests python-no-log-warn restrict-start_date rst-backticks
2009-
setup-order setup-installation shellcheck sort-in-the-wild stylelint
2008+
pydocstyle pylint pylint-tests python-no-log-warn pyupgrade restrict-start_date
2009+
rst-backticks setup-order setup-installation shellcheck sort-in-the-wild stylelint
20102010
trailing-whitespace update-breeze-file update-extras update-local-yml-file
20112011
update-setup-cfg-file yamllint
20122012

STATIC_CODE_CHECKS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ require Breeze Docker images to be installed locally:
9494
----------------------------------- ---------------------------------------------------------------- ------------
9595
``fix-encoding-pragma`` Removes encoding header from python files.
9696
----------------------------------- ---------------------------------------------------------------- ------------
97+
``pyupgrade`` Runs PyUpgrade
98+
----------------------------------- ---------------------------------------------------------------- ------------
9799
``flake8`` Runs flake8. *
98100
----------------------------------- ---------------------------------------------------------------- ------------
99101
``forbid-tabs`` Fails if tabs are used in the project.

airflow/api/auth/backend/kerberos_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def init_app(app):
7979

8080
service = 'airflow'
8181

82-
_KERBEROS_SERVICE.service_name = "{}@{}".format(service, hostname)
82+
_KERBEROS_SERVICE.service_name = f"{service}@{hostname}"
8383

8484
if 'KRB5_KTNAME' not in os.environ:
8585
os.environ['KRB5_KTNAME'] = conf.get('kerberos', 'keytab')

airflow/api/client/json_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _request(self, url, method='GET', json=None):
4343
return resp.json()
4444

4545
def trigger_dag(self, dag_id, run_id=None, conf=None, execution_date=None):
46-
endpoint = '/api/experimental/dags/{}/dag_runs'.format(dag_id)
46+
endpoint = f'/api/experimental/dags/{dag_id}/dag_runs'
4747
url = urljoin(self._api_base_url, endpoint)
4848
data = self._request(url, method='POST',
4949
json={
@@ -54,13 +54,13 @@ def trigger_dag(self, dag_id, run_id=None, conf=None, execution_date=None):
5454
return data['message']
5555

5656
def delete_dag(self, dag_id):
57-
endpoint = '/api/experimental/dags/{}/delete_dag'.format(dag_id)
57+
endpoint = f'/api/experimental/dags/{dag_id}/delete_dag'
5858
url = urljoin(self._api_base_url, endpoint)
5959
data = self._request(url, method='DELETE')
6060
return data['message']
6161

6262
def get_pool(self, name):
63-
endpoint = '/api/experimental/pools/{}'.format(name)
63+
endpoint = f'/api/experimental/pools/{name}'
6464
url = urljoin(self._api_base_url, endpoint)
6565
pool = self._request(url)
6666
return pool['pool'], pool['slots'], pool['description']
@@ -83,7 +83,7 @@ def create_pool(self, name, slots, description):
8383
return pool['pool'], pool['slots'], pool['description']
8484

8585
def delete_pool(self, name):
86-
endpoint = '/api/experimental/pools/{}'.format(name)
86+
endpoint = f'/api/experimental/pools/{name}'
8787
url = urljoin(self._api_base_url, endpoint)
8888
pool = self._request(url, method='DELETE')
8989
return pool['pool'], pool['slots'], pool['description']

airflow/api/client/local_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def trigger_dag(self, dag_id, run_id=None, conf=None, execution_date=None):
3030
run_id=run_id,
3131
conf=conf,
3232
execution_date=execution_date)
33-
return "Created {}".format(dag_run)
33+
return f"Created {dag_run}"
3434

3535
def delete_dag(self, dag_id):
3636
count = delete_dag.delete_dag(dag_id)
37-
return "Removed {} record(s)".format(count)
37+
return f"Removed {count} record(s)"
3838

3939
def get_pool(self, name):
4040
the_pool = pool.get_pool(name=name)

airflow/api/common/experimental/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ def check_and_get_dag(dag_id: str, task_id: Optional[str] = None) -> DagModel:
2727
"""Checks that DAG exists and in case it is specified that Task exist"""
2828
dag_model = DagModel.get_current(dag_id)
2929
if dag_model is None:
30-
raise DagNotFound("Dag id {} not found in DagModel".format(dag_id))
30+
raise DagNotFound(f"Dag id {dag_id} not found in DagModel")
3131

3232
dagbag = DagBag(
3333
dag_folder=dag_model.fileloc,
3434
read_dags_from_db=True
3535
)
3636
dag = dagbag.get_dag(dag_id)
3737
if not dag:
38-
error_message = "Dag id {} not found".format(dag_id)
38+
error_message = f"Dag id {dag_id} not found"
3939
raise DagNotFound(error_message)
4040
if task_id and not dag.has_task(task_id):
41-
error_message = 'Task {} not found in dag {}'.format(task_id, dag_id)
41+
error_message = f'Task {task_id} not found in dag {dag_id}'
4242
raise TaskNotFound(error_message)
4343
return dag
4444

airflow/api/common/experimental/delete_dag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> i
4242
log.info("Deleting DAG: %s", dag_id)
4343
dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first()
4444
if dag is None:
45-
raise DagNotFound("Dag id {} not found".format(dag_id))
45+
raise DagNotFound(f"Dag id {dag_id} not found")
4646

4747
# Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval.
4848
# There may be a lag, so explicitly removes serialized DAG here.

airflow/api/common/experimental/mark_tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ def set_state(
9494
return []
9595

9696
if not timezone.is_localized(execution_date):
97-
raise ValueError("Received non-localized date {}".format(execution_date))
97+
raise ValueError(f"Received non-localized date {execution_date}")
9898

9999
task_dags = {task.dag for task in tasks}
100100
if len(task_dags) > 1:
101-
raise ValueError("Received tasks from multiple DAGs: {}".format(task_dags))
101+
raise ValueError(f"Received tasks from multiple DAGs: {task_dags}")
102102
dag = next(iter(task_dags))
103103
if dag is None:
104104
raise ValueError("Received tasks with no DAG")
@@ -247,7 +247,7 @@ def get_execution_dates(dag, execution_date, future, past):
247247
"""Returns dates of DAG execution"""
248248
latest_execution_date = dag.get_latest_execution_date()
249249
if latest_execution_date is None:
250-
raise ValueError("Received non-localized date {}".format(execution_date))
250+
raise ValueError(f"Received non-localized date {execution_date}")
251251
# determine date range of dag runs and tasks to consider
252252
end_date = latest_execution_date if future else execution_date
253253
if 'start_date' in dag.default_args:

airflow/api/common/experimental/trigger_dag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _trigger_dag(
4848
dag = dag_bag.get_dag(dag_id) # prefetch dag if it is stored serialized
4949

5050
if dag_id not in dag_bag.dags:
51-
raise DagNotFound("Dag id {} not found".format(dag_id))
51+
raise DagNotFound(f"Dag id {dag_id} not found")
5252

5353
execution_date = execution_date if execution_date else timezone.utcnow()
5454

@@ -62,7 +62,7 @@ def _trigger_dag(
6262
min_dag_start_date = dag.default_args["start_date"]
6363
if min_dag_start_date and execution_date < min_dag_start_date:
6464
raise ValueError(
65-
"The execution_date [{0}] should be >= start_date [{1}] from DAG's default_args".format(
65+
"The execution_date [{}] should be >= start_date [{}] from DAG's default_args".format(
6666
execution_date.isoformat(),
6767
min_dag_start_date.isoformat()))
6868

@@ -112,7 +112,7 @@ def trigger_dag(
112112
"""
113113
dag_model = DagModel.get_current(dag_id)
114114
if dag_model is None:
115-
raise DagNotFound("Dag id {} not found in DagModel".format(dag_id))
115+
raise DagNotFound(f"Dag id {dag_id} not found in DagModel")
116116

117117
dagbag = DagBag(dag_folder=dag_model.fileloc, read_dags_from_db=True)
118118
triggers = _trigger_dag(

0 commit comments

Comments
 (0)