Skip to content

Commit 2dff30a

Browse files
committed
Merge remote-tracking branch 'origin/uk/no_ticket/forbid_artcles' into uk/no_ticket/forbid_artcles
2 parents 5ecef68 + b075a92 commit 2dff30a

21 files changed

+139
-469
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ on:
88

99
jobs:
1010
main-windows:
11-
uses: asottile/workflows/.github/workflows/tox.yml@v1.7.0
11+
uses: asottile/workflows/.github/workflows/tox.yml@v1.8.1
1212
with:
13-
env: '["py39"]'
13+
env: '["py310"]'
1414
os: windows-latest
1515
main-linux:
16-
uses: asottile/workflows/.github/workflows/tox.yml@v1.7.0
16+
uses: asottile/workflows/.github/workflows/tox.yml@v1.8.1
1717
with:
18-
env: '["py39", "py310", "py311", "py312"]'
18+
env: '["py310", "py311", "py312", "py313"]'
1919
os: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 10 additions & 10 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: v5.0.0
3+
rev: v6.0.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -10,32 +10,32 @@ repos:
1010
- id: name-tests-test
1111
- id: requirements-txt-fixer
1212
- repo: https://github.com/asottile/setup-cfg-fmt
13-
rev: v2.5.0
13+
rev: v3.1.0
1414
hooks:
1515
- id: setup-cfg-fmt
1616
- repo: https://github.com/asottile/reorder-python-imports
17-
rev: v3.13.0
17+
rev: v3.16.0
1818
hooks:
1919
- id: reorder-python-imports
20-
args: [--py39-plus, --add-import, 'from __future__ import annotations']
20+
args: [--py310-plus, --add-import, 'from __future__ import annotations']
2121
- repo: https://github.com/asottile/add-trailing-comma
22-
rev: v3.1.0
22+
rev: v4.0.0
2323
hooks:
2424
- id: add-trailing-comma
2525
- repo: https://github.com/asottile/pyupgrade
26-
rev: v3.17.0
26+
rev: v3.21.2
2727
hooks:
2828
- id: pyupgrade
29-
args: [--py39-plus]
29+
args: [--py310-plus]
3030
- repo: https://github.com/hhatto/autopep8
31-
rev: v2.3.1
31+
rev: v2.3.2
3232
hooks:
3333
- id: autopep8
3434
- repo: https://github.com/PyCQA/flake8
35-
rev: 7.1.1
35+
rev: 7.3.0
3636
hooks:
3737
- id: flake8
3838
- repo: https://github.com/pre-commit/mirrors-mypy
39-
rev: v1.11.2
39+
rev: v1.19.1
4040
hooks:
4141
- id: mypy

.pre-commit-hooks.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
language: python
1313
types: [python]
1414
- id: check-byte-order-marker
15-
name: 'check BOM - deprecated: use fix-byte-order-marker'
16-
description: forbids files which have a utf-8 byte-order marker.
17-
entry: check-byte-order-marker
15+
name: check-byte-order-marker (removed)
16+
description: (removed) use fix-byte-order-marker instead.
17+
entry: pre-commit-hooks-removed check-byte-order-marker fix-byte-order-marker https://github.com/pre-commit/pre-commit-hooks
1818
language: python
1919
types: [text]
2020
- id: check-builtin-literals
@@ -29,7 +29,7 @@
2929
entry: check-case-conflict
3030
language: python
3131
- id: check-docstring-first
32-
name: check docstring is first
32+
name: check docstring is first (deprecated)
3333
description: checks a common error of defining a docstring after code.
3434
entry: check-docstring-first
3535
language: python
@@ -155,10 +155,10 @@
155155
language: python
156156
types: [text]
157157
- id: fix-encoding-pragma
158-
name: fix python encoding pragma (deprecated)
159-
description: 'adds # -*- coding: utf-8 -*- to the top of python files.'
158+
name: fix python encoding pragma (removed)
159+
description: (removed) use pyupgrade instead.
160+
entry: pre-commit-hooks-removed fix-encoding-pragma pyupgrade https://github.com/asottile/pyupgrade
160161
language: python
161-
entry: fix-encoding-pragma
162162
types: [python]
163163
- id: forbid-new-submodules
164164
name: forbid new submodules

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
6.0.0 - 2025-08-09
2+
==================
3+
4+
## Fixes
5+
- `check-shebang-scripts-are-executable`: improve error message.
6+
- #1115 PR by @homebysix.
7+
8+
## Migrating
9+
- now requires python >= 3.9.
10+
- #1098 PR by @asottile.
11+
- `file-contents-sorter`: disallow `--unique` and `--ignore-case` at the same
12+
time.
13+
- #1095 PR by @nemacysts.
14+
- #794 issue by @teksturi.
15+
- Removed `check-byte-order-marker` and `fix-encoding-pragma`.
16+
- `check-byte-order-marker`: migrate to `fix-byte-order-marker`.
17+
- `fix-encoding-pragma`: migrate to `pyupgrade`.
18+
- #1034 PR by @mxr.
19+
- #1032 issue by @mxr.
20+
- #522 PR by @jgowdy.
21+
122
5.0.0 - 2024-10-05
223
==================
324

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Add this to your `.pre-commit-config.yaml`
1515

1616
```yaml
1717
- repo: https://github.com/pre-commit/pre-commit-hooks
18-
rev: v5.0.0 # Use the ref you want to point at
18+
rev: v6.0.0 # Use the ref you want to point at
1919
hooks:
2020
- id: trailing-whitespace
2121
# - id: ...
@@ -45,9 +45,6 @@ Require literal syntax when initializing empty or zero Python builtin types.
4545
#### `check-case-conflict`
4646
Check for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT.
4747

48-
#### `check-docstring-first`
49-
Checks for a common error of placing code before the docstring.
50-
5148
#### `check-executables-have-shebangs`
5249
Checks that non-binary executables have a proper shebang.
5350

@@ -129,13 +126,6 @@ The following arguments are available:
129126
#### `fix-byte-order-marker`
130127
removes UTF-8 byte order marker
131128

132-
#### `fix-encoding-pragma`
133-
134-
_Deprecated since py2 is EOL - use [pyupgrade](https://github.com/asottile/pyupgrade) instead._
135-
136-
Add `# -*- coding: utf-8 -*-` to the top of python files.
137-
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
138-
139129
#### `forbid-new-submodules`
140130
Prevent addition of new git submodules.
141131

@@ -213,6 +203,9 @@ Trims trailing whitespace.
213203
### Deprecated / replaced hooks
214204

215205
- `check-byte-order-marker`: instead use fix-byte-order-marker
206+
- `fix-encoding-pragma`: instead use [`pyupgrade`](https://github.com/asottile/pyupgrade)
207+
- `check-docstring-first`: fundamentally flawed, deprecated without replacement.
208+
216209

217210
### As a standalone package
218211

pre_commit_hooks/check_builtin_literals.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,37 @@ class Call(NamedTuple):
2626
class Visitor(ast.NodeVisitor):
2727
def __init__(
2828
self,
29-
ignore: Sequence[str] | None = None,
29+
ignore: set[str],
3030
allow_dict_kwargs: bool = True,
3131
) -> None:
3232
self.builtin_type_calls: list[Call] = []
33-
self.ignore = set(ignore) if ignore else set()
3433
self.allow_dict_kwargs = allow_dict_kwargs
34+
self._disallowed = BUILTIN_TYPES.keys() - ignore
3535

3636
def _check_dict_call(self, node: ast.Call) -> bool:
3737
return self.allow_dict_kwargs and bool(node.keywords)
3838

3939
def visit_Call(self, node: ast.Call) -> None:
40-
if not isinstance(node.func, ast.Name):
40+
if (
4141
# Ignore functions that are object attributes (`foo.bar()`).
4242
# Assume that if the user calls `builtins.list()`, they know what
4343
# they're doing.
44-
return
45-
if node.func.id not in set(BUILTIN_TYPES).difference(self.ignore):
46-
return
47-
if node.func.id == 'dict' and self._check_dict_call(node):
48-
return
49-
elif node.args:
50-
return
51-
self.builtin_type_calls.append(
52-
Call(node.func.id, node.lineno, node.col_offset),
53-
)
44+
isinstance(node.func, ast.Name) and
45+
node.func.id in self._disallowed and
46+
(node.func.id != 'dict' or not self._check_dict_call(node)) and
47+
not node.args
48+
):
49+
self.builtin_type_calls.append(
50+
Call(node.func.id, node.lineno, node.col_offset),
51+
)
52+
53+
self.generic_visit(node)
5454

5555

5656
def check_file(
5757
filename: str,
58-
ignore: Sequence[str] | None = None,
58+
*,
59+
ignore: set[str],
5960
allow_dict_kwargs: bool = True,
6061
) -> list[Call]:
6162
with open(filename, 'rb') as f:

pre_commit_hooks/check_byte_order_marker.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

pre_commit_hooks/check_shebang_scripts_are_executable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _message(path: str) -> None:
3636
f'`chmod +x {shlex.quote(path)}`\n'
3737
f' If on Windows, you may also need to: '
3838
f'`git add --chmod=+x {shlex.quote(path)}`\n'
39-
f' If it not supposed to be executable, double-check its shebang '
39+
f' If it is not supposed to be executable, double-check its shebang '
4040
f'is wanted.\n',
4141
file=sys.stderr,
4242
)

pre_commit_hooks/file_contents_sorter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from __future__ import annotations
1313

1414
import argparse
15+
from collections.abc import Callable
1516
from collections.abc import Iterable
1617
from collections.abc import Sequence
1718
from typing import Any
18-
from typing import Callable
1919
from typing import IO
2020

2121
PASS = 0
@@ -54,18 +54,21 @@ def sort_file_contents(
5454
def main(argv: Sequence[str] | None = None) -> int:
5555
parser = argparse.ArgumentParser()
5656
parser.add_argument('filenames', nargs='+', help='Files to sort')
57-
parser.add_argument(
57+
58+
mutex = parser.add_mutually_exclusive_group(required=False)
59+
mutex.add_argument(
5860
'--ignore-case',
5961
action='store_const',
6062
const=bytes.lower,
6163
default=None,
6264
help='fold lower case to upper case characters',
6365
)
64-
parser.add_argument(
66+
mutex.add_argument(
6567
'--unique',
6668
action='store_true',
6769
help='ensure each line is unique',
6870
)
71+
6972
args = parser.parse_args(argv)
7073

7174
retv = PASS

0 commit comments

Comments
 (0)