Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04de6a2

Browse files
author
Anthony Sottile
committed
drop python 3.6 support
python 3.6 reached end of life on 2021-12-23
1 parent d3bdf14 commit 04de6a2

111 files changed

Lines changed: 401 additions & 286 deletions

File tree

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ repos:
2828
rev: v2.31.0
2929
hooks:
3030
- id: pyupgrade
31-
args: [--py36-plus]
31+
args: [--py37-plus]
3232
- repo: https://github.com/asottile/reorder_python_imports
3333
rev: v2.6.0
3434
hooks:
3535
- id: reorder-python-imports
36-
args: [--py3-plus]
36+
args: [--py37-plus, --add-import, 'from __future__ import annotations']
37+
exclude: ^testing/resources/python3_hooks_repo/
3738
- repo: https://github.com/asottile/add-trailing-comma
3839
rev: v2.2.1
3940
hooks:

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
displayName: install R
5151
- template: job--python-tox.yml@asottile
5252
parameters:
53-
toxenvs: [pypy3, py36, py37, py38, py39]
53+
toxenvs: [py37, py38, py39]
5454
os: linux
5555
pre_test:
5656
- task: UseRubyVersion@0

pre_commit/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from pre_commit.main import main
24

35

pre_commit/clientlib.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import functools
35
import logging
46
import re
57
import shlex
68
import sys
79
from typing import Any
8-
from typing import Dict
9-
from typing import Optional
1010
from typing import Sequence
1111

1212
import cfgv
@@ -95,7 +95,7 @@ class InvalidManifestError(FatalError):
9595
)
9696

9797

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

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

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

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

136136

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

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

155155

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

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

186-
def check(self, dct: Dict[str, Any]) -> None:
186+
def check(self, dct: dict[str, Any]) -> None:
187187
if dct.get('repo') in {LOCAL, META}:
188188
self._cond('rev').check(dct)
189189
self._cond('sha').check(dct)
@@ -194,7 +194,7 @@ def check(self, dct: Dict[str, Any]) -> None:
194194
else:
195195
self._cond('rev').check(dct)
196196

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

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

219219

220220
def warn_unknown_keys_repo(
221221
extra: Sequence[str],
222222
orig_keys: Sequence[str],
223-
dct: Dict[str, str],
223+
dct: dict[str, str],
224224
) -> None:
225225
logger.warning(
226226
f'Unexpected key(s) present on {dct["repo"]}: {", ".join(extra)}',
@@ -253,7 +253,7 @@ def warn_unknown_keys_repo(
253253

254254

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

@@ -377,7 +377,7 @@ class InvalidConfigError(FatalError):
377377
pass
378378

379379

380-
def ordered_load_normalize_legacy_config(contents: str) -> Dict[str, Any]:
380+
def ordered_load_normalize_legacy_config(contents: str) -> dict[str, Any]:
381381
data = yaml_load(contents)
382382
if isinstance(data, list):
383383
logger.warning(
@@ -398,7 +398,7 @@ def ordered_load_normalize_legacy_config(contents: str) -> Dict[str, Any]:
398398
)
399399

400400

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

pre_commit/color.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import os
35
import sys

pre_commit/commands/autoupdate.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
from __future__ import annotations
2+
13
import os.path
24
import re
35
from typing import Any
4-
from typing import Dict
5-
from typing import List
66
from typing import NamedTuple
7-
from typing import Optional
87
from typing import Sequence
9-
from typing import Tuple
108

119
import pre_commit.constants as C
1210
from pre_commit import git
@@ -29,13 +27,13 @@
2927
class RevInfo(NamedTuple):
3028
repo: str
3129
rev: str
32-
frozen: Optional[str]
30+
frozen: str | None
3331

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

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

4139
if tags_only:
@@ -76,7 +74,7 @@ class RepositoryCannotBeUpdatedError(RuntimeError):
7674

7775

7876
def _check_hooks_still_exist_at_rev(
79-
repo_config: Dict[str, Any],
77+
repo_config: dict[str, Any],
8078
info: RevInfo,
8179
store: Store,
8280
) -> None:
@@ -101,9 +99,9 @@ def _check_hooks_still_exist_at_rev(
10199

102100
def _original_lines(
103101
path: str,
104-
rev_infos: List[Optional[RevInfo]],
102+
rev_infos: list[RevInfo | None],
105103
retry: bool = False,
106-
) -> Tuple[List[str], List[int]]:
104+
) -> tuple[list[str], list[int]]:
107105
"""detect `rev:` lines or reformat the file"""
108106
with open(path, newline='') as f:
109107
original = f.read()
@@ -120,7 +118,7 @@ def _original_lines(
120118
return _original_lines(path, rev_infos, retry=True)
121119

122120

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

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

158156
config = load_config(config_file)

pre_commit/commands/clean.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os.path
24

35
from pre_commit import output

pre_commit/commands/gc.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
from __future__ import annotations
2+
13
import os.path
24
from typing import Any
3-
from typing import Dict
4-
from typing import Set
5-
from typing import Tuple
65

76
import pre_commit.constants as C
87
from pre_commit import output
@@ -17,9 +16,9 @@
1716

1817
def _mark_used_repos(
1918
store: Store,
20-
all_repos: Dict[Tuple[str, str], str],
21-
unused_repos: Set[Tuple[str, str]],
22-
repo: Dict[str, Any],
19+
all_repos: dict[tuple[str, str], str],
20+
unused_repos: set[tuple[str, str]],
21+
repo: dict[str, Any],
2322
) -> None:
2423
if repo['repo'] == META:
2524
return

pre_commit/commands/hook_impl.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import os.path
35
import subprocess
46
import sys
5-
from typing import Optional
67
from typing import Sequence
7-
from typing import Tuple
88

99
from pre_commit.commands.run import run
1010
from pre_commit.envcontext import envcontext
@@ -18,7 +18,7 @@ def _run_legacy(
1818
hook_type: str,
1919
hook_dir: str,
2020
args: Sequence[str],
21-
) -> Tuple[int, bytes]:
21+
) -> tuple[int, bytes]:
2222
if os.environ.get('PRE_COMMIT_RUNNING_LEGACY'):
2323
raise SystemExit(
2424
f"bug: pre-commit's script is installed in migration mode\n"
@@ -69,16 +69,16 @@ def _ns(
6969
color: bool,
7070
*,
7171
all_files: bool = False,
72-
remote_branch: Optional[str] = None,
73-
local_branch: Optional[str] = None,
74-
from_ref: Optional[str] = None,
75-
to_ref: Optional[str] = None,
76-
remote_name: Optional[str] = None,
77-
remote_url: Optional[str] = None,
78-
commit_msg_filename: Optional[str] = None,
79-
checkout_type: Optional[str] = None,
80-
is_squash_merge: Optional[str] = None,
81-
rewrite_command: Optional[str] = None,
72+
remote_branch: str | None = None,
73+
local_branch: str | None = None,
74+
from_ref: str | None = None,
75+
to_ref: str | None = None,
76+
remote_name: str | None = None,
77+
remote_url: str | None = None,
78+
commit_msg_filename: str | None = None,
79+
checkout_type: str | None = None,
80+
is_squash_merge: str | None = None,
81+
rewrite_command: str | None = None,
8282
) -> argparse.Namespace:
8383
return argparse.Namespace(
8484
color=color,
@@ -109,7 +109,7 @@ def _pre_push_ns(
109109
color: bool,
110110
args: Sequence[str],
111111
stdin: bytes,
112-
) -> Optional[argparse.Namespace]:
112+
) -> argparse.Namespace | None:
113113
remote_name = args[0]
114114
remote_url = args[1]
115115

@@ -197,7 +197,7 @@ def _run_ns(
197197
color: bool,
198198
args: Sequence[str],
199199
stdin: bytes,
200-
) -> Optional[argparse.Namespace]:
200+
) -> argparse.Namespace | None:
201201
_check_args_length(hook_type, args)
202202
if hook_type == 'pre-push':
203203
return _pre_push_ns(color, args, stdin)

pre_commit/commands/init_templatedir.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os.path
35
from typing import Sequence

0 commit comments

Comments
 (0)