Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop python 3.6 support #2215

Merged
merged 1 commit into from Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -28,12 +28,13 @@ repos:
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: [--py3-plus]
args: [--py37-plus, --add-import, 'from __future__ import annotations']
exclude: ^testing/resources/python3_hooks_repo/
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.2.1
hooks:
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Expand Up @@ -50,7 +50,7 @@ jobs:
displayName: install R
- template: job--python-tox.yml@asottile
parameters:
toxenvs: [pypy3, py36, py37, py38, py39]
toxenvs: [py37, py38, py39]
os: linux
pre_test:
- task: UseRubyVersion@0
Expand Down
2 changes: 2 additions & 0 deletions pre_commit/__main__.py
@@ -1,3 +1,5 @@
from __future__ import annotations

from pre_commit.main import main


Expand Down
26 changes: 13 additions & 13 deletions pre_commit/clientlib.py
@@ -1,12 +1,12 @@
from __future__ import annotations

import argparse
import functools
import logging
import re
import shlex
import sys
from typing import Any
from typing import Dict
from typing import Optional
from typing import Sequence

import cfgv
Expand Down Expand Up @@ -95,7 +95,7 @@ class InvalidManifestError(FatalError):
)


def validate_manifest_main(argv: Optional[Sequence[str]] = None) -> int:
def validate_manifest_main(argv: Sequence[str] | None = None) -> int:
parser = _make_argparser('Manifest filenames.')
args = parser.parse_args(argv)

Expand All @@ -116,7 +116,7 @@ def validate_manifest_main(argv: Optional[Sequence[str]] = None) -> int:

# should inherit from cfgv.Conditional if sha support is dropped
class WarnMutableRev(cfgv.ConditionalOptional):
def check(self, dct: Dict[str, Any]) -> None:
def check(self, dct: dict[str, Any]) -> None:
super().check(dct)

if self.key in dct:
Expand All @@ -135,7 +135,7 @@ def check(self, dct: Dict[str, Any]) -> None:


class OptionalSensibleRegexAtHook(cfgv.OptionalNoDefault):
def check(self, dct: Dict[str, Any]) -> None:
def check(self, dct: dict[str, Any]) -> None:
super().check(dct)

if '/*' in dct.get(self.key, ''):
Expand All @@ -154,7 +154,7 @@ def check(self, dct: Dict[str, Any]) -> None:


class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
def check(self, dct: Dict[str, Any]) -> None:
def check(self, dct: dict[str, Any]) -> None:
super().check(dct)

if '/*' in dct.get(self.key, ''):
Expand Down Expand Up @@ -183,7 +183,7 @@ def _cond(key: str) -> cfgv.Conditional:
ensure_absent=True,
)

def check(self, dct: Dict[str, Any]) -> None:
def check(self, dct: dict[str, Any]) -> None:
if dct.get('repo') in {LOCAL, META}:
self._cond('rev').check(dct)
self._cond('sha').check(dct)
Expand All @@ -194,7 +194,7 @@ def check(self, dct: Dict[str, Any]) -> None:
else:
self._cond('rev').check(dct)

def apply_default(self, dct: Dict[str, Any]) -> None:
def apply_default(self, dct: dict[str, Any]) -> None:
if 'sha' in dct:
dct['rev'] = dct.pop('sha')

Expand All @@ -212,15 +212,15 @@ def _entry(modname: str) -> str:
def warn_unknown_keys_root(
extra: Sequence[str],
orig_keys: Sequence[str],
dct: Dict[str, str],
dct: dict[str, str],
) -> None:
logger.warning(f'Unexpected key(s) present at root: {", ".join(extra)}')


def warn_unknown_keys_repo(
extra: Sequence[str],
orig_keys: Sequence[str],
dct: Dict[str, str],
dct: dict[str, str],
) -> None:
logger.warning(
f'Unexpected key(s) present on {dct["repo"]}: {", ".join(extra)}',
Expand Down Expand Up @@ -253,7 +253,7 @@ def warn_unknown_keys_repo(


class NotAllowed(cfgv.OptionalNoDefault):
def check(self, dct: Dict[str, Any]) -> None:
def check(self, dct: dict[str, Any]) -> None:
if self.key in dct:
raise cfgv.ValidationError(f'{self.key!r} cannot be overridden')

Expand Down Expand Up @@ -377,7 +377,7 @@ class InvalidConfigError(FatalError):
pass


def ordered_load_normalize_legacy_config(contents: str) -> Dict[str, Any]:
def ordered_load_normalize_legacy_config(contents: str) -> dict[str, Any]:
data = yaml_load(contents)
if isinstance(data, list):
logger.warning(
Expand All @@ -398,7 +398,7 @@ def ordered_load_normalize_legacy_config(contents: str) -> Dict[str, Any]:
)


def validate_config_main(argv: Optional[Sequence[str]] = None) -> int:
def validate_config_main(argv: Sequence[str] | None = None) -> int:
parser = _make_argparser('Config filenames.')
args = parser.parse_args(argv)

Expand Down
2 changes: 2 additions & 0 deletions pre_commit/color.py
@@ -1,3 +1,5 @@
from __future__ import annotations

import argparse
import os
import sys
Expand Down
22 changes: 10 additions & 12 deletions pre_commit/commands/autoupdate.py
@@ -1,12 +1,10 @@
from __future__ import annotations

import os.path
import re
from typing import Any
from typing import Dict
from typing import List
from typing import NamedTuple
from typing import Optional
from typing import Sequence
from typing import Tuple

import pre_commit.constants as C
from pre_commit import git
Expand All @@ -29,13 +27,13 @@
class RevInfo(NamedTuple):
repo: str
rev: str
frozen: Optional[str]
frozen: str | None

@classmethod
def from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
def from_config(cls, config: dict[str, Any]) -> RevInfo:
return cls(config['repo'], config['rev'], None)

def update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
def update(self, tags_only: bool, freeze: bool) -> RevInfo:
git_cmd = ('git', *git.NO_FS_MONITOR)

if tags_only:
Expand Down Expand Up @@ -76,7 +74,7 @@ class RepositoryCannotBeUpdatedError(RuntimeError):


def _check_hooks_still_exist_at_rev(
repo_config: Dict[str, Any],
repo_config: dict[str, Any],
info: RevInfo,
store: Store,
) -> None:
Expand All @@ -101,9 +99,9 @@ def _check_hooks_still_exist_at_rev(

def _original_lines(
path: str,
rev_infos: List[Optional[RevInfo]],
rev_infos: list[RevInfo | None],
retry: bool = False,
) -> Tuple[List[str], List[int]]:
) -> tuple[list[str], list[int]]:
"""detect `rev:` lines or reformat the file"""
with open(path, newline='') as f:
original = f.read()
Expand All @@ -120,7 +118,7 @@ def _original_lines(
return _original_lines(path, rev_infos, retry=True)


def _write_new_config(path: str, rev_infos: List[Optional[RevInfo]]) -> None:
def _write_new_config(path: str, rev_infos: list[RevInfo | None]) -> None:
lines, idxs = _original_lines(path, rev_infos)

for idx, rev_info in zip(idxs, rev_infos):
Expand Down Expand Up @@ -152,7 +150,7 @@ def autoupdate(
"""Auto-update the pre-commit config to the latest versions of repos."""
migrate_config(config_file, quiet=True)
retv = 0
rev_infos: List[Optional[RevInfo]] = []
rev_infos: list[RevInfo | None] = []
changed = False

config = load_config(config_file)
Expand Down
2 changes: 2 additions & 0 deletions pre_commit/commands/clean.py
@@ -1,3 +1,5 @@
from __future__ import annotations

import os.path

from pre_commit import output
Expand Down
11 changes: 5 additions & 6 deletions pre_commit/commands/gc.py
@@ -1,8 +1,7 @@
from __future__ import annotations

import os.path
from typing import Any
from typing import Dict
from typing import Set
from typing import Tuple

import pre_commit.constants as C
from pre_commit import output
Expand All @@ -17,9 +16,9 @@

def _mark_used_repos(
store: Store,
all_repos: Dict[Tuple[str, str], str],
unused_repos: Set[Tuple[str, str]],
repo: Dict[str, Any],
all_repos: dict[tuple[str, str], str],
unused_repos: set[tuple[str, str]],
repo: dict[str, Any],
) -> None:
if repo['repo'] == META:
return
Expand Down
30 changes: 15 additions & 15 deletions pre_commit/commands/hook_impl.py
@@ -1,10 +1,10 @@
from __future__ import annotations

import argparse
import os.path
import subprocess
import sys
from typing import Optional
from typing import Sequence
from typing import Tuple

from pre_commit.commands.run import run
from pre_commit.envcontext import envcontext
Expand All @@ -18,7 +18,7 @@ def _run_legacy(
hook_type: str,
hook_dir: str,
args: Sequence[str],
) -> Tuple[int, bytes]:
) -> tuple[int, bytes]:
if os.environ.get('PRE_COMMIT_RUNNING_LEGACY'):
raise SystemExit(
f"bug: pre-commit's script is installed in migration mode\n"
Expand Down Expand Up @@ -69,16 +69,16 @@ def _ns(
color: bool,
*,
all_files: bool = False,
remote_branch: Optional[str] = None,
local_branch: Optional[str] = None,
from_ref: Optional[str] = None,
to_ref: Optional[str] = None,
remote_name: Optional[str] = None,
remote_url: Optional[str] = None,
commit_msg_filename: Optional[str] = None,
checkout_type: Optional[str] = None,
is_squash_merge: Optional[str] = None,
rewrite_command: Optional[str] = None,
remote_branch: str | None = None,
local_branch: str | None = None,
from_ref: str | None = None,
to_ref: str | None = None,
remote_name: str | None = None,
remote_url: str | None = None,
commit_msg_filename: str | None = None,
checkout_type: str | None = None,
is_squash_merge: str | None = None,
rewrite_command: str | None = None,
) -> argparse.Namespace:
return argparse.Namespace(
color=color,
Expand Down Expand Up @@ -109,7 +109,7 @@ def _pre_push_ns(
color: bool,
args: Sequence[str],
stdin: bytes,
) -> Optional[argparse.Namespace]:
) -> argparse.Namespace | None:
remote_name = args[0]
remote_url = args[1]

Expand Down Expand Up @@ -197,7 +197,7 @@ def _run_ns(
color: bool,
args: Sequence[str],
stdin: bytes,
) -> Optional[argparse.Namespace]:
) -> argparse.Namespace | None:
_check_args_length(hook_type, args)
if hook_type == 'pre-push':
return _pre_push_ns(color, args, stdin)
Expand Down
2 changes: 2 additions & 0 deletions pre_commit/commands/init_templatedir.py
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging
import os.path
from typing import Sequence
Expand Down
12 changes: 6 additions & 6 deletions pre_commit/commands/install_uninstall.py
@@ -1,11 +1,11 @@
from __future__ import annotations

import logging
import os.path
import shlex
import shutil
import sys
from typing import Optional
from typing import Sequence
from typing import Tuple

from pre_commit import git
from pre_commit import output
Expand Down Expand Up @@ -34,8 +34,8 @@

def _hook_paths(
hook_type: str,
git_dir: Optional[str] = None,
) -> Tuple[str, str]:
git_dir: str | None = None,
) -> tuple[str, str]:
git_dir = git_dir if git_dir is not None else git.get_git_dir()
pth = os.path.join(git_dir, 'hooks', hook_type)
return pth, f'{pth}.legacy'
Expand All @@ -54,7 +54,7 @@ def _install_hook_script(
hook_type: str,
overwrite: bool = False,
skip_on_missing_config: bool = False,
git_dir: Optional[str] = None,
git_dir: str | None = None,
) -> None:
hook_path, legacy_path = _hook_paths(hook_type, git_dir=git_dir)

Expand Down Expand Up @@ -107,7 +107,7 @@ def install(
overwrite: bool = False,
hooks: bool = False,
skip_on_missing_config: bool = False,
git_dir: Optional[str] = None,
git_dir: str | None = None,
) -> int:
if git_dir is None and git.has_core_hookpaths_set():
logger.error(
Expand Down
2 changes: 2 additions & 0 deletions pre_commit/commands/migrate_config.py
@@ -1,3 +1,5 @@
from __future__ import annotations

import re
import textwrap

Expand Down