X Tutup
Skip to content

Commit b2faf33

Browse files
authored
Merge pull request pre-commit#1277 from pre-commit/pyupgrade
Drop python 2 / python3.5 support in pre-commit
2 parents 764c765 + 76a184e commit b2faf33

File tree

101 files changed

+1281
-1041
lines changed

Some content is hidden

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

101 files changed

+1281
-1041
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ exclude_lines =
2525
^\s*return NotImplemented\b
2626
^\s*raise$
2727

28+
# Ignore typing-related things
29+
^if (False|TYPE_CHECKING):
30+
: \.\.\.$
31+
2832
# Don't complain if non-runnable code isn't run:
2933
^if __name__ == ['"]__main__['"]:$
3034

.gitignore

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
*.egg-info
2-
*.iml
32
*.py[co]
4-
.*.sw[a-z]
5-
.coverage
6-
.idea
7-
.project
8-
.pydevproject
9-
.tox
10-
.venv.touch
3+
/.coverage
4+
/.mypy_cache
5+
/.pytest_cache
6+
/.tox
7+
/dist
118
/venv*
12-
coverage-html
13-
dist
14-
.pytest_cache

.pre-commit-config.yaml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.1.0
3+
rev: v2.4.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -12,30 +12,41 @@ repos:
1212
- id: requirements-txt-fixer
1313
- id: double-quote-string-fixer
1414
- repo: https://gitlab.com/pycqa/flake8
15-
rev: 3.7.7
15+
rev: 3.7.9
1616
hooks:
1717
- id: flake8
1818
- repo: https://github.com/pre-commit/mirrors-autopep8
19-
rev: v1.4.3
19+
rev: v1.4.4
2020
hooks:
2121
- id: autopep8
2222
- repo: https://github.com/pre-commit/pre-commit
23-
rev: v1.14.4
23+
rev: v1.21.0
2424
hooks:
2525
- id: validate_manifest
2626
- repo: https://github.com/asottile/pyupgrade
27-
rev: v1.12.0
27+
rev: v1.25.3
2828
hooks:
2929
- id: pyupgrade
30+
args: [--py36-plus]
3031
- repo: https://github.com/asottile/reorder_python_imports
31-
rev: v1.4.0
32+
rev: v1.9.0
3233
hooks:
3334
- id: reorder-python-imports
34-
language_version: python3
35+
args: [--py3-plus]
3536
- repo: https://github.com/asottile/add-trailing-comma
36-
rev: v1.0.0
37+
rev: v1.5.0
3738
hooks:
3839
- id: add-trailing-comma
40+
args: [--py36-plus]
41+
- repo: https://github.com/asottile/setup-cfg-fmt
42+
rev: v1.6.0
43+
hooks:
44+
- id: setup-cfg-fmt
45+
- repo: https://github.com/pre-commit/mirrors-mypy
46+
rev: v0.761
47+
hooks:
48+
- id: mypy
49+
exclude: ^testing/resources/
3950
- repo: meta
4051
hooks:
4152
- id: check-hooks-apply

azure-pipelines.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ resources:
1010
type: github
1111
endpoint: github
1212
name: asottile/azure-pipeline-templates
13-
ref: refs/tags/v0.0.15
13+
ref: refs/tags/v1.0.0
1414

1515
jobs:
1616
- template: job--pre-commit.yml@asottile
1717
- template: job--python-tox.yml@asottile
1818
parameters:
19-
toxenvs: [py27, py37]
19+
toxenvs: [py37]
2020
os: windows
2121
additional_variables:
2222
COVERAGE_IGNORE_WINDOWS: '# pragma: windows no cover'
2323
TOX_TESTENV_PASSENV: COVERAGE_IGNORE_WINDOWS
24-
TEMP: C:\Temp # remove when dropping python2
2524
pre_test:
2625
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
2726
displayName: Add conda to PATH
@@ -39,7 +38,7 @@ jobs:
3938
displayName: install swift
4039
- template: job--python-tox.yml@asottile
4140
parameters:
42-
toxenvs: [pypy, pypy3, py27, py36, py37, py38]
41+
toxenvs: [pypy3, py36, py37, py38]
4342
os: linux
4443
pre_test:
4544
- task: UseRubyVersion@0

pre_commit/__main__.py

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

53

pre_commit/clientlib.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from __future__ import absolute_import
2-
from __future__ import unicode_literals
3-
41
import argparse
52
import functools
63
import logging
74
import pipes
85
import sys
6+
from typing import Any
7+
from typing import Dict
8+
from typing import Optional
9+
from typing import Sequence
910

1011
import cfgv
1112
from aspy.yaml import ordered_load
@@ -21,15 +22,15 @@
2122
check_string_regex = cfgv.check_and(cfgv.check_string, cfgv.check_regex)
2223

2324

24-
def check_type_tag(tag):
25+
def check_type_tag(tag: str) -> None:
2526
if tag not in ALL_TAGS:
2627
raise cfgv.ValidationError(
2728
'Type tag {!r} is not recognized. '
2829
'Try upgrading identify and pre-commit?'.format(tag),
2930
)
3031

3132

32-
def check_min_version(version):
33+
def check_min_version(version: str) -> None:
3334
if parse_version(version) > parse_version(C.VERSION):
3435
raise cfgv.ValidationError(
3536
'pre-commit version {} is required but version {} is installed. '
@@ -39,7 +40,7 @@ def check_min_version(version):
3940
)
4041

4142

42-
def _make_argparser(filenames_help):
43+
def _make_argparser(filenames_help: str) -> argparse.ArgumentParser:
4344
parser = argparse.ArgumentParser()
4445
parser.add_argument('filenames', nargs='*', help=filenames_help)
4546
parser.add_argument('-V', '--version', action='version', version=C.VERSION)
@@ -89,7 +90,7 @@ class InvalidManifestError(FatalError):
8990
)
9091

9192

92-
def validate_manifest_main(argv=None):
93+
def validate_manifest_main(argv: Optional[Sequence[str]] = None) -> int:
9394
parser = _make_argparser('Manifest filenames.')
9495
args = parser.parse_args(argv)
9596
ret = 0
@@ -106,19 +107,19 @@ def validate_manifest_main(argv=None):
106107
META = 'meta'
107108

108109

109-
class MigrateShaToRev(object):
110+
class MigrateShaToRev:
110111
key = 'rev'
111112

112113
@staticmethod
113-
def _cond(key):
114+
def _cond(key: str) -> cfgv.Conditional:
114115
return cfgv.Conditional(
115116
key, cfgv.check_string,
116117
condition_key='repo',
117118
condition_value=cfgv.NotIn(LOCAL, META),
118119
ensure_absent=True,
119120
)
120121

121-
def check(self, dct):
122+
def check(self, dct: Dict[str, Any]) -> None:
122123
if dct.get('repo') in {LOCAL, META}:
123124
self._cond('rev').check(dct)
124125
self._cond('sha').check(dct)
@@ -129,14 +130,14 @@ def check(self, dct):
129130
else:
130131
self._cond('rev').check(dct)
131132

132-
def apply_default(self, dct):
133+
def apply_default(self, dct: Dict[str, Any]) -> None:
133134
if 'sha' in dct:
134135
dct['rev'] = dct.pop('sha')
135136

136137
remove_default = cfgv.Required.remove_default
137138

138139

139-
def _entry(modname):
140+
def _entry(modname: str) -> str:
140141
"""the hook `entry` is passed through `shlex.split()` by the command
141142
runner, so to prevent issues with spaces and backslashes (on Windows)
142143
it must be quoted here.
@@ -146,13 +147,21 @@ def _entry(modname):
146147
)
147148

148149

149-
def warn_unknown_keys_root(extra, orig_keys, dct):
150+
def warn_unknown_keys_root(
151+
extra: Sequence[str],
152+
orig_keys: Sequence[str],
153+
dct: Dict[str, str],
154+
) -> None:
150155
logger.warning(
151156
'Unexpected key(s) present at root: {}'.format(', '.join(extra)),
152157
)
153158

154159

155-
def warn_unknown_keys_repo(extra, orig_keys, dct):
160+
def warn_unknown_keys_repo(
161+
extra: Sequence[str],
162+
orig_keys: Sequence[str],
163+
dct: Dict[str, str],
164+
) -> None:
156165
logger.warning(
157166
'Unexpected key(s) present on {}: {}'.format(
158167
dct['repo'], ', '.join(extra),
@@ -202,7 +211,7 @@ def warn_unknown_keys_repo(extra, orig_keys, dct):
202211
if item.key in {'name', 'language', 'entry'} else
203212
item
204213
for item in MANIFEST_HOOK_DICT.items
205-
])
214+
]),
206215
)
207216
CONFIG_HOOK_DICT = cfgv.Map(
208217
'Hook', 'id',
@@ -217,7 +226,7 @@ def warn_unknown_keys_repo(extra, orig_keys, dct):
217226
cfgv.OptionalNoDefault(item.key, item.check_fn)
218227
for item in MANIFEST_HOOK_DICT.items
219228
if item.key != 'id'
220-
]
229+
],
221230
)
222231
CONFIG_REPO_DICT = cfgv.Map(
223232
'Repository', 'repo',
@@ -243,7 +252,7 @@ def warn_unknown_keys_repo(extra, orig_keys, dct):
243252
DEFAULT_LANGUAGE_VERSION = cfgv.Map(
244253
'DefaultLanguageVersion', None,
245254
cfgv.NoAdditionalKeys(all_languages),
246-
*[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages]
255+
*[cfgv.Optional(x, cfgv.check_string, C.DEFAULT) for x in all_languages],
247256
)
248257
CONFIG_SCHEMA = cfgv.Map(
249258
'Config', None,
@@ -284,7 +293,7 @@ class InvalidConfigError(FatalError):
284293
pass
285294

286295

287-
def ordered_load_normalize_legacy_config(contents):
296+
def ordered_load_normalize_legacy_config(contents: str) -> Dict[str, Any]:
288297
data = ordered_load(contents)
289298
if isinstance(data, list):
290299
# TODO: Once happy, issue a deprecation warning and instructions
@@ -301,7 +310,7 @@ def ordered_load_normalize_legacy_config(contents):
301310
)
302311

303312

304-
def validate_config_main(argv=None):
313+
def validate_config_main(argv: Optional[Sequence[str]] = None) -> int:
305314
parser = _make_argparser('Config filenames.')
306315
args = parser.parse_args(argv)
307316
ret = 0

pre_commit/color.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from __future__ import unicode_literals
2-
31
import os
42
import sys
53

64
terminal_supports_color = True
7-
if os.name == 'nt': # pragma: no cover (windows)
5+
if sys.platform == 'win32': # pragma: no cover (windows)
86
from pre_commit.color_windows import enable_virtual_terminal_processing
97
try:
108
enable_virtual_terminal_processing()
11-
except WindowsError:
9+
except OSError:
1210
terminal_supports_color = False
1311

1412
RED = '\033[41m'
@@ -23,7 +21,7 @@ class InvalidColorSetting(ValueError):
2321
pass
2422

2523

26-
def format_color(text, color, use_color_setting):
24+
def format_color(text: str, color: str, use_color_setting: bool) -> str:
2725
"""Format text with color.
2826
2927
Args:
@@ -34,13 +32,13 @@ def format_color(text, color, use_color_setting):
3432
if not use_color_setting:
3533
return text
3634
else:
37-
return '{}{}{}'.format(color, text, NORMAL)
35+
return f'{color}{text}{NORMAL}'
3836

3937

4038
COLOR_CHOICES = ('auto', 'always', 'never')
4139

4240

43-
def use_color(setting):
41+
def use_color(setting: str) -> bool:
4442
"""Choose whether to use color based on the command argument.
4543
4644
Args:

pre_commit/color_windows.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from __future__ import absolute_import
2-
from __future__ import unicode_literals
3-
4-
from ctypes import POINTER
5-
from ctypes import windll
6-
from ctypes import WinError
7-
from ctypes import WINFUNCTYPE
8-
from ctypes.wintypes import BOOL
9-
from ctypes.wintypes import DWORD
10-
from ctypes.wintypes import HANDLE
1+
import sys
2+
assert sys.platform == 'win32'
3+
4+
from ctypes import POINTER # noqa: E402
5+
from ctypes import windll # noqa: E402
6+
from ctypes import WinError # noqa: E402
7+
from ctypes import WINFUNCTYPE # noqa: E402
8+
from ctypes.wintypes import BOOL # noqa: E402
9+
from ctypes.wintypes import DWORD # noqa: E402
10+
from ctypes.wintypes import HANDLE # noqa: E402
11+
1112

1213
STD_OUTPUT_HANDLE = -11
1314
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4

0 commit comments

Comments
 (0)
X Tutup