Skip to content

Commit 14654ca

Browse files
authored
Merge pull request #407 from kurtmckee/update-pre-commit-hooks
Update pre-commit hooks
2 parents 118ad61 + dfe942b commit 14654ca

File tree

20 files changed

+72
-92
lines changed

20 files changed

+72
-92
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
default_stages: [commit, push]
2+
default_stages: [pre-commit, pre-push]
33
default_language_version:
44
# force all unspecified python hooks to run python3
55
python: python3
@@ -10,37 +10,22 @@ repos:
1010
- id: check-hooks-apply
1111

1212
- repo: https://github.com/asottile/pyupgrade
13-
rev: v2.19.0
13+
rev: v3.21.2
1414
hooks:
1515
- id: pyupgrade
16-
args: ["--py36-plus"]
16+
args: ["--py39-plus"]
1717

18-
- repo: local
18+
- repo: https://github.com/psf/black-pre-commit-mirror
19+
rev: 25.12.0
1920
hooks:
20-
- id: flynt
21-
name: Convert to f-strings with flynt
22-
entry: flynt
23-
language: python
24-
additional_dependencies: ['flynt==0.76']
25-
2621
- id: black
27-
name: black
28-
entry: black
29-
language: system
30-
require_serial: true
31-
types: [python]
3222

23+
- repo: https://github.com/pycqa/isort
24+
rev: 7.0.0
25+
hooks:
3326
- id: isort
34-
name: isort
35-
entry: isort
36-
args: ['--filter-files']
37-
language: system
38-
require_serial: true
39-
types: [python]
4027

41-
- id: pyflakes
42-
name: pyflakes
43-
entry: pyflakes
44-
language: system
45-
require_serial: true
46-
types: [python]
28+
- repo: https://github.com/pycqa/flake8
29+
rev: 7.3.0
30+
hooks:
31+
- id: flake8

openapi_spec_validator/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""OpenAPI spec validator module."""
2+
23
from openapi_spec_validator.shortcuts import validate
34
from openapi_spec_validator.shortcuts import validate_spec
45
from openapi_spec_validator.shortcuts import validate_spec_url

openapi_spec_validator/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22
import sys
33
from argparse import ArgumentParser
4+
from collections.abc import Sequence
45
from typing import Optional
5-
from typing import Sequence
66

77
from jsonschema.exceptions import ValidationError
88
from jsonschema.exceptions import best_match

openapi_spec_validator/readers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import sys
22
from os import path
33
from pathlib import Path
4-
from typing import Tuple
54

65
from jsonschema_path.handlers import all_urls_handler
76
from jsonschema_path.handlers import file_handler
87
from jsonschema_path.typing import Schema
98

109

11-
def read_from_stdin(filename: str) -> Tuple[Schema, str]:
10+
def read_from_stdin(filename: str) -> tuple[Schema, str]:
1211
return file_handler(sys.stdin), "" # type: ignore
1312

1413

15-
def read_from_filename(filename: str) -> Tuple[Schema, str]:
14+
def read_from_filename(filename: str) -> tuple[Schema, str]:
1615
if not path.isfile(filename):
1716
raise OSError(f"No such file: {filename}")
1817

openapi_spec_validator/schemas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""OpenAIP spec validator schemas module."""
2+
23
from functools import partial
34

45
from jsonschema.validators import Draft4Validator

openapi_spec_validator/schemas/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""OpenAIP spec validator schemas utils module."""
2+
23
from importlib.resources import as_file
34
from importlib.resources import files
45
from os import path
5-
from typing import Tuple
66

77
from jsonschema_path.readers import FilePathReader
88
from jsonschema_path.typing import Schema
99

1010

11-
def get_schema(version: str) -> Tuple[Schema, str]:
11+
def get_schema(version: str) -> tuple[Schema, str]:
1212
schema_path = f"resources/schemas/v{version}/schema.json"
1313
ref = files("openapi_spec_validator") / schema_path
1414
with as_file(ref) as resource_path:

openapi_spec_validator/shortcuts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""OpenAPI spec validator shortcuts module."""
2+
23
import warnings
3-
from typing import Mapping
4+
from collections.abc import Mapping
45
from typing import Optional
5-
from typing import Type
66

77
from jsonschema_path import SchemaPath
88
from jsonschema_path.handlers import all_urls_handler
@@ -50,7 +50,7 @@ def validate(
5050

5151
def validate_url(
5252
spec_url: str,
53-
cls: Optional[Type[SpecValidator]] = None,
53+
cls: Optional[type[SpecValidator]] = None,
5454
) -> None:
5555
spec = all_urls_handler(spec_url)
5656
return validate(spec, base_uri=spec_url, cls=cls)
@@ -82,7 +82,7 @@ def validate_spec(
8282
def validate_spec_url(
8383
spec_url: str,
8484
validator: Optional[SupportsValidation] = None,
85-
cls: Optional[Type[SpecValidator]] = None,
85+
cls: Optional[type[SpecValidator]] = None,
8686
) -> None:
8787
warnings.warn(
8888
"validate_spec_url shortcut is deprecated. Use validate_url instead.",

openapi_spec_validator/validation/caches.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
from collections.abc import Iterable
2+
from collections.abc import Iterator
13
from typing import Generic
2-
from typing import Iterable
3-
from typing import Iterator
4-
from typing import List
54
from typing import TypeVar
65

76
T = TypeVar("T")
@@ -14,7 +13,7 @@ class CachedIterable(Iterable[T], Generic[T]):
1413
It should not be iterated by his own.
1514
"""
1615

17-
cache: List[T]
16+
cache: list[T]
1817
iter: Iterator[T]
1918
completed: bool
2019

openapi_spec_validator/validation/decorators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""OpenAPI spec validator validation decorators module."""
2+
23
import logging
4+
from collections.abc import Iterable
5+
from collections.abc import Iterator
36
from functools import wraps
47
from typing import Any
58
from typing import Callable
6-
from typing import Iterable
7-
from typing import Iterator
89
from typing import TypeVar
910

1011
from jsonschema.exceptions import ValidationError
@@ -19,7 +20,7 @@
1920

2021

2122
def wraps_errors(
22-
func: Callable[..., Any]
23+
func: Callable[..., Any],
2324
) -> Callable[..., Iterator[ValidationError]]:
2425
@wraps(func)
2526
def wrapper(*args: Any, **kwds: Any) -> Iterator[ValidationError]:
@@ -35,7 +36,7 @@ def wrapper(*args: Any, **kwds: Any) -> Iterator[ValidationError]:
3536

3637

3738
def wraps_cached_iter(
38-
func: Callable[[Args], Iterator[T]]
39+
func: Callable[[Args], Iterator[T]],
3940
) -> Callable[[Args], CachedIterable[T]]:
4041
@wraps(func)
4142
def wrapper(*args: Any, **kwargs: Any) -> CachedIterable[T]:
@@ -46,7 +47,7 @@ def wrapper(*args: Any, **kwargs: Any) -> CachedIterable[T]:
4647

4748

4849
def unwraps_iter(
49-
func: Callable[[Args], Iterable[T]]
50+
func: Callable[[Args], Iterable[T]],
5051
) -> Callable[[Args], Iterator[T]]:
5152
@wraps(func)
5253
def wrapper(*args: Any, **kwargs: Any) -> Iterator[T]:

openapi_spec_validator/validation/keywords.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import string
2+
from collections.abc import Iterator
3+
from collections.abc import Sequence
24
from typing import TYPE_CHECKING
35
from typing import Any
4-
from typing import Sequence
5-
from typing import Iterator
6-
from typing import List
76
from typing import Optional
87
from typing import cast
98

@@ -68,7 +67,7 @@ class SchemaValidator(KeywordValidator):
6867
def __init__(self, registry: "KeywordValidatorRegistry"):
6968
super().__init__(registry)
7069

71-
self.schema_ids_registry: Optional[List[int]] = []
70+
self.schema_ids_registry: Optional[list[int]] = []
7271

7372
@property
7473
def default_validator(self) -> ValueValidator:
@@ -113,8 +112,9 @@ def __call__(
113112
all_of = schema / "allOf"
114113
for inner_schema in all_of:
115114
yield from self(inner_schema, require_properties=False)
116-
nested_properties += list(self._collect_properties(inner_schema))
117-
115+
nested_properties += list(
116+
self._collect_properties(inner_schema)
117+
)
118118

119119
if "anyOf" in schema:
120120
any_of = schema / "anyOf"
@@ -154,8 +154,12 @@ def __call__(
154154
require_properties=False,
155155
)
156156

157-
required = "required" in schema and (schema / "required").read_value() or []
158-
properties = "properties" in schema and (schema / "properties").keys() or []
157+
required = (
158+
"required" in schema and (schema / "required").read_value() or []
159+
)
160+
properties = (
161+
"properties" in schema and (schema / "properties").keys() or []
162+
)
159163
if "allOf" in schema:
160164
extra_properties = list(
161165
set(required) - set(properties) - set(nested_properties)
@@ -305,7 +309,7 @@ class OperationValidator(KeywordValidator):
305309
def __init__(self, registry: "KeywordValidatorRegistry"):
306310
super().__init__(registry)
307311

308-
self.operation_ids_registry: Optional[List[str]] = []
312+
self.operation_ids_registry: Optional[list[str]] = []
309313

310314
@property
311315
def responses_validator(self) -> ResponsesValidator:
@@ -356,8 +360,7 @@ def __call__(
356360
for path in self._get_path_params_from_url(url):
357361
if path not in all_params:
358362
yield UnresolvableParameterError(
359-
"Path parameter '{}' for '{}' operation in '{}' "
360-
"was not resolved".format(path, name, url)
363+
f"Path parameter '{path}' for '{name}' operation in '{url}' was not resolved"
361364
)
362365
return
363366

0 commit comments

Comments
 (0)