Skip to content

Commit

Permalink
Merge pull request #719 from pre-commit/all-repos_autofix_drop-py36
Browse files Browse the repository at this point in the history
drop python3.6 support
  • Loading branch information
asottile authored Jan 16, 2022
2 parents 2aef4c7 + 8f61529 commit 77dcefc
Show file tree
Hide file tree
Showing 76 changed files with 229 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ repos:
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: [--py3-plus]
args: [--py37-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.2.1
hooks:
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resources:
type: github
endpoint: github
name: asottile/azure-pipeline-templates
ref: refs/tags/v2.1.0
ref: refs/tags/v2.4.0

jobs:
- template: job--python-tox.yml@asottile
Expand All @@ -19,5 +19,5 @@ jobs:
os: windows
- template: job--python-tox.yml@asottile
parameters:
toxenvs: [pypy3, py36, py37, py38]
toxenvs: [py37, py38, py39, py310]
os: linux
8 changes: 4 additions & 4 deletions pre_commit_hooks/check_added_large_files.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

import argparse
import math
import os
import subprocess
from typing import Optional
from typing import Sequence
from typing import Set

from pre_commit_hooks.util import added_files
from pre_commit_hooks.util import zsplit


def filter_lfs_files(filenames: Set[str]) -> None: # pragma: no cover (lfs)
def filter_lfs_files(filenames: set[str]) -> None: # pragma: no cover (lfs)
"""Remove files tracked by git-lfs from the set."""
if not filenames:
return
Expand Down Expand Up @@ -54,7 +54,7 @@ def find_large_added_files(
return retv


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
'filenames', nargs='*',
Expand Down
5 changes: 3 additions & 2 deletions pre_commit_hooks/check_ast.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

import argparse
import ast
import platform
import sys
import traceback
from typing import Optional
from typing import Sequence


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv)
Expand Down
17 changes: 8 additions & 9 deletions pre_commit_hooks/check_builtin_literals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

import argparse
import ast
from typing import List
from typing import NamedTuple
from typing import Optional
from typing import Sequence
from typing import Set


BUILTIN_TYPES = {
Expand All @@ -27,10 +26,10 @@ class Call(NamedTuple):
class Visitor(ast.NodeVisitor):
def __init__(
self,
ignore: Optional[Sequence[str]] = None,
ignore: Sequence[str] | None = None,
allow_dict_kwargs: bool = True,
) -> None:
self.builtin_type_calls: List[Call] = []
self.builtin_type_calls: list[Call] = []
self.ignore = set(ignore) if ignore else set()
self.allow_dict_kwargs = allow_dict_kwargs

Expand All @@ -56,21 +55,21 @@ def visit_Call(self, node: ast.Call) -> None:

def check_file(
filename: str,
ignore: Optional[Sequence[str]] = None,
ignore: Sequence[str] | None = None,
allow_dict_kwargs: bool = True,
) -> List[Call]:
) -> list[Call]:
with open(filename, 'rb') as f:
tree = ast.parse(f.read(), filename=filename)
visitor = Visitor(ignore=ignore, allow_dict_kwargs=allow_dict_kwargs)
visitor.visit(tree)
return visitor.builtin_type_calls


def parse_ignore(value: str) -> Set[str]:
def parse_ignore(value: str) -> set[str]:
return set(value.split(','))


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
parser.add_argument('--ignore', type=parse_ignore, default=set())
Expand Down
5 changes: 3 additions & 2 deletions pre_commit_hooks/check_byte_order_marker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import argparse
from typing import Optional
from typing import Sequence


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check')
args = parser.parse_args(argv)
Expand Down
10 changes: 5 additions & 5 deletions pre_commit_hooks/check_case_conflict.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from __future__ import annotations

import argparse
from typing import Iterable
from typing import Iterator
from typing import Optional
from typing import Sequence
from typing import Set

from pre_commit_hooks.util import added_files
from pre_commit_hooks.util import cmd_output


def lower_set(iterable: Iterable[str]) -> Set[str]:
def lower_set(iterable: Iterable[str]) -> set[str]:
return {x.lower() for x in iterable}


Expand All @@ -21,7 +21,7 @@ def parents(file: str) -> Iterator[str]:
path_parts.pop()


def directories_for(files: Set[str]) -> Set[str]:
def directories_for(files: set[str]) -> set[str]:
return {parent for file in files for parent in parents(file)}


Expand Down Expand Up @@ -56,7 +56,7 @@ def find_conflicting_filenames(filenames: Sequence[str]) -> int:
return retv


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
'filenames', nargs='*',
Expand Down
5 changes: 3 additions & 2 deletions pre_commit_hooks/check_docstring_first.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import argparse
import io
import tokenize
from tokenize import tokenize as tokenize_tokenize
from typing import Optional
from typing import Sequence

NON_CODE_TOKENS = frozenset((
Expand Down Expand Up @@ -45,7 +46,7 @@ def check_docstring_first(src: bytes, filename: str = '<unknown>') -> int:
return 0


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv)
Expand Down
11 changes: 5 additions & 6 deletions pre_commit_hooks/check_executables_have_shebangs.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""Check that executable text files have a shebang."""
from __future__ import annotations

import argparse
import shlex
import sys
from typing import Generator
from typing import List
from typing import NamedTuple
from typing import Optional
from typing import Sequence
from typing import Set

from pre_commit_hooks.util import cmd_output
from pre_commit_hooks.util import zsplit

EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7'))


def check_executables(paths: List[str]) -> int:
def check_executables(paths: list[str]) -> int:
if sys.platform == 'win32': # pragma: win32 cover
return _check_git_filemode(paths)
else: # pragma: win32 no cover
Expand All @@ -42,7 +41,7 @@ def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:


def _check_git_filemode(paths: Sequence[str]) -> int:
seen: Set[str] = set()
seen: set[str] = set()
for ls_file in git_ls_files(paths):
is_executable = any(b in EXECUTABLE_VALUES for b in ls_file.mode[-3:])
if is_executable and not has_shebang(ls_file.filename):
Expand Down Expand Up @@ -71,7 +70,7 @@ def _message(path: str) -> None:
)


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv)
Expand Down
12 changes: 5 additions & 7 deletions pre_commit_hooks/check_json.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from __future__ import annotations

import argparse
import json
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Sequence
from typing import Tuple


def raise_duplicate_keys(
ordered_pairs: List[Tuple[str, Any]],
) -> Dict[str, Any]:
ordered_pairs: list[tuple[str, Any]],
) -> dict[str, Any]:
d = {}
for key, val in ordered_pairs:
if key in d:
Expand All @@ -20,7 +18,7 @@ def raise_duplicate_keys(
return d


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
args = parser.parse_args(argv)
Expand Down
5 changes: 3 additions & 2 deletions pre_commit_hooks/check_merge_conflict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import argparse
import os.path
from typing import Optional
from typing import Sequence

from pre_commit_hooks.util import cmd_output
Expand All @@ -26,7 +27,7 @@ def is_in_merge() -> bool:
)


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
parser.add_argument('--assume-in-merge', action='store_true')
Expand Down
11 changes: 5 additions & 6 deletions pre_commit_hooks/check_shebang_scripts_are_executable.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
"""Check that text files with a shebang are executable."""
from __future__ import annotations

import argparse
import shlex
import sys
from typing import List
from typing import Optional
from typing import Sequence
from typing import Set

from pre_commit_hooks.check_executables_have_shebangs import EXECUTABLE_VALUES
from pre_commit_hooks.check_executables_have_shebangs import git_ls_files
from pre_commit_hooks.check_executables_have_shebangs import has_shebang


def check_shebangs(paths: List[str]) -> int:
def check_shebangs(paths: list[str]) -> int:
# Cannot optimize on non-executability here if we intend this check to
# work on win32 -- and that's where problems caused by non-executability
# (elsewhere) are most likely to arise from.
return _check_git_filemode(paths)


def _check_git_filemode(paths: Sequence[str]) -> int:
seen: Set[str] = set()
seen: set[str] = set()
for ls_file in git_ls_files(paths):
is_executable = any(b in EXECUTABLE_VALUES for b in ls_file.mode[-3:])
if not is_executable and has_shebang(ls_file.filename):
Expand All @@ -41,7 +40,7 @@ def _message(path: str) -> None:
)


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv)
Expand Down
5 changes: 3 additions & 2 deletions pre_commit_hooks/check_symlinks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import argparse
import os.path
from typing import Optional
from typing import Sequence


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description='Checks for broken symlinks.')
parser.add_argument('filenames', nargs='*', help='Filenames to check')
args = parser.parse_args(argv)
Expand Down
5 changes: 3 additions & 2 deletions pre_commit_hooks/check_toml.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import argparse
from typing import Optional
from typing import Sequence

import toml


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
args = parser.parse_args(argv)
Expand Down
8 changes: 4 additions & 4 deletions pre_commit_hooks/check_vcs_permalinks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import argparse
import re
import sys
from typing import List
from typing import Optional
from typing import Pattern
from typing import Sequence

Expand All @@ -15,7 +15,7 @@ def _get_pattern(domain: str) -> Pattern[bytes]:
return re.compile(regex.encode())


def _check_filename(filename: str, patterns: List[Pattern[bytes]]) -> int:
def _check_filename(filename: str, patterns: list[Pattern[bytes]]) -> int:
retv = 0
with open(filename, 'rb') as f:
for i, line in enumerate(f, 1):
Expand All @@ -28,7 +28,7 @@ def _check_filename(filename: str, patterns: List[Pattern[bytes]]) -> int:
return retv


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
parser.add_argument(
Expand Down
Loading

0 comments on commit 77dcefc

Please sign in to comment.