Skip to content

Commit

Permalink
Add __future__.annotations automatically by isort (#26383)
Browse files Browse the repository at this point in the history
This is a follow up after #26289 and 26290 to automatically add
__future__.annotations import to all new files (except empty __init__).

Also the isort configureation is moved to pyproject toml to be
consistent across manual and pre-commit runs of isort
  • Loading branch information
potiuk committed Sep 14, 2022
1 parent b816a6b commit 4216799
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 32 deletions.
14 changes: 1 addition & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ repos:
# __future__ annotations, so it should be left without automated upgrade
# BaseOperator is disabled because replacing ClassVar[List[Type with corresponding list/type causes the attr to fail
# see https://github.com/apache/airflow/pull/26290#issuecomment-1246014807
exclude: ^airflow/_vendor/|^airflow/providers/google/cloud/hooks/gcs.py$|^test/decorators/test_python.py$|^airflow/models/baseoperator.py$
exclude: ^airflow/_vendor/|^airflow/providers/google/cloud/hooks/gcs.py$|^tests/decorators/test_python.py$|^airflow/models/baseoperator.py$
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
Expand All @@ -242,18 +242,6 @@ repos:
hooks:
- id: isort
name: Run isort to sort imports in Python files
files: \.py$|\.pyi$
# To keep consistent with the global isort skip config defined in setup.cfg
exclude: ^airflow/_vendor/|^build/.*$|^venv/.*$|^\.tox/.*$
args:
# These -p options are duplicated to known_first_party in setup.cfg,
# Please keep these in sync for now. (See comments there for details.)
- -p=airflow
- -p=airflow_breeze
- -p=docker_tests
- -p=docs
- -p=kubernetes_tests
- -p=tests
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
Expand Down
2 changes: 2 additions & 0 deletions airflow/migrations/versions/0009_1_6_0_dagrun_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
Create Date: 2015-10-29 08:36:31.726728
"""
from __future__ import annotations

import sqlalchemy as sa
from alembic import op

Expand Down
13 changes: 7 additions & 6 deletions dev/airflow-github
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
# This tool is based on the Spark merge_spark_pr script:
# https://github.com/apache/spark/blob/master/dev/merge_spark_pr.py

from __future__ import annotations

import re
import sys
from collections import Counter, defaultdict
from typing import List, Optional

import git
import rich_click as click
Expand Down Expand Up @@ -70,7 +71,7 @@ def get_issue_type(issue):
return issue_type


def get_commit_in_main_associated_with_pr(repo: git.Repo, issue: Issue) -> Optional[str]:
def get_commit_in_main_associated_with_pr(repo: git.Repo, issue: Issue) -> str | None:
"""For a PR, find the associated merged commit & return its SHA"""
if issue.pull_request:
commit = repo.git.log(f"--grep=#{issue.number}", "origin/main", "--format=%H")
Expand All @@ -84,7 +85,7 @@ def get_commit_in_main_associated_with_pr(repo: git.Repo, issue: Issue) -> Optio
return None


def is_cherrypicked(repo: git.Repo, issue: Issue, previous_version: Optional[str] = None) -> bool:
def is_cherrypicked(repo: git.Repo, issue: Issue, previous_version: str | None = None) -> bool:
"""Check if a given issue is cherry-picked in the current branch or not"""
log_args = ['--format=%H', f"--grep=#{issue.number}"]
if previous_version:
Expand All @@ -100,12 +101,12 @@ def is_pr(issue: Issue) -> bool:
return "apache/airflow/pull/" in issue.html_url


def files_touched(repo, commit_id: str) -> List[str]:
def files_touched(repo, commit_id: str) -> list[str]:
real_commit = repo.commit(commit_id)
return real_commit.stats.files.keys()


def is_core_commit(files: List[str]) -> bool:
def is_core_commit(files: list[str]) -> bool:
# We list out things that _aren't_ core files,
# and we want to know if the commit changes anything
# outside of these designated-non-core files
Expand Down Expand Up @@ -219,7 +220,7 @@ def compare(target_version, github_token, previous_version=None, show_uncherrypi
repo = git.Repo(".", search_parent_directories=True)

github_handler = Github(github_token)
milestone_issues: List[Issue] = list(
milestone_issues: list[Issue] = list(
github_handler.search_issues(f"repo:apache/airflow milestone:\"Airflow {target_version}\"")
)

Expand Down
2 changes: 2 additions & 0 deletions dev/airflow-license
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

import os
import re
import string
Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
866390aad1d155c75b4283c4d50ff56fb1f210f21dcd0e0955984bd08f26ac5c
b3211bf16ef6ae93fc4a4cfeb2acffc0e2f3a8f476d76148d543f2751aff2c5d
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ skip-string-normalization = true
[build-system]
requires = ['setuptools==63.4.3']
build-backend = "setuptools.build_meta"
[tool.isort]
add_imports = ["from __future__ import annotations"]
append_only = true
line_length = 110
combine_as_imports = true
default_section = "THIRDPARTY"
known_first_party = ["airflow", "airflow_breeze", "docker_tests", "docs", "kubernetes_tests", "tests"]
# The test_python.py is needed because adding __future__.annotations breaks runtime checks that are
# needed for the test to work
skip = ["build", ".tox", "venv", "tests/decorators/test_python.py"]
skip_glob = ["*.pyi"]
profile = "black"
2 changes: 2 additions & 0 deletions scripts/ci/runners/sync_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

import re

import requests
Expand Down
12 changes: 0 additions & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,3 @@ ignore_errors = True
# Most of them don't but even if they do, it does not matter
[mypy-google.cloud.*]
no_implicit_optional = False

[isort]
line_length=110
combine_as_imports = true
default_section = THIRDPARTY
# This is duplicated with arguments in .pre-commit-config.yaml because isort is
# having some issues picking up these config files. Please keep these in sync
# for now and track the isort issue: https://github.com/PyCQA/isort/issues/1889
known_first_party = airflow,airflow_breeze,docker_tests,docs,kubernetes_tests,tests
# Need to be consistent with the exclude config defined in pre-commit-config.yaml
skip = build,.tox,venv
profile = black
2 changes: 2 additions & 0 deletions tests/task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
# specific language governing permissions and limitations
# under the License.
# flake8: noqa
from __future__ import annotations

from .task_runner import *

0 comments on commit 4216799

Please sign in to comment.