Skip to content
Prev Previous commit
Next Next commit
Run pre-commit run pyupgrade -a
  • Loading branch information
kurtmckee committed Jun 23, 2025
commit 4b996e7b7c49d49c4d450c0773dabad7519fd32c
2 changes: 1 addition & 1 deletion openapi_spec_validator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from argparse import ArgumentParser
from typing import Optional
from typing import Sequence
from collections.abc import Sequence

from jsonschema.exceptions import ValidationError
from jsonschema.exceptions import best_match
Expand Down
4 changes: 2 additions & 2 deletions openapi_spec_validator/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from jsonschema_path.typing import Schema


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


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

Expand Down
2 changes: 1 addition & 1 deletion openapi_spec_validator/schemas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from jsonschema_path.typing import Schema


def get_schema(version: str) -> Tuple[Schema, str]:
def get_schema(version: str) -> tuple[Schema, str]:
schema_path = f"resources/schemas/v{version}/schema.json"
ref = files("openapi_spec_validator") / schema_path
with as_file(ref) as resource_path:
Expand Down
6 changes: 3 additions & 3 deletions openapi_spec_validator/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""OpenAPI spec validator shortcuts module."""
import warnings
from typing import Mapping
from collections.abc import Mapping
from typing import Optional
from typing import Type

Expand Down Expand Up @@ -50,7 +50,7 @@ def validate(

def validate_url(
spec_url: str,
cls: Optional[Type[SpecValidator]] = None,
cls: Optional[type[SpecValidator]] = None,
) -> None:
spec = all_urls_handler(spec_url)
return validate(spec, base_uri=spec_url, cls=cls)
Expand Down Expand Up @@ -82,7 +82,7 @@ def validate_spec(
def validate_spec_url(
spec_url: str,
validator: Optional[SupportsValidation] = None,
cls: Optional[Type[SpecValidator]] = None,
cls: Optional[type[SpecValidator]] = None,
) -> None:
warnings.warn(
"validate_spec_url shortcut is deprecated. Use validate_url instead.",
Expand Down
6 changes: 3 additions & 3 deletions openapi_spec_validator/validation/caches.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Generic
from typing import Iterable
from typing import Iterator
from collections.abc import Iterable
from collections.abc import Iterator
from typing import List
from typing import TypeVar

Expand All @@ -14,7 +14,7 @@ class CachedIterable(Iterable[T], Generic[T]):
It should not be iterated by his own.
"""

cache: List[T]
cache: list[T]
iter: Iterator[T]
completed: bool

Expand Down
4 changes: 2 additions & 2 deletions openapi_spec_validator/validation/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from functools import wraps
from typing import Any
from typing import Callable
from typing import Iterable
from typing import Iterator
from collections.abc import Iterable
from collections.abc import Iterator
from typing import TypeVar

from jsonschema.exceptions import ValidationError
Expand Down
11 changes: 5 additions & 6 deletions openapi_spec_validator/validation/keywords.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import string
from typing import TYPE_CHECKING
from typing import Any
from typing import Sequence
from typing import Iterator
from collections.abc import Sequence
from collections.abc import Iterator
from typing import List
from typing import Optional
from typing import cast
Expand Down Expand Up @@ -68,7 +68,7 @@ class SchemaValidator(KeywordValidator):
def __init__(self, registry: "KeywordValidatorRegistry"):
super().__init__(registry)

self.schema_ids_registry: Optional[List[int]] = []
self.schema_ids_registry: Optional[list[int]] = []

@property
def default_validator(self) -> ValueValidator:
Expand Down Expand Up @@ -305,7 +305,7 @@ class OperationValidator(KeywordValidator):
def __init__(self, registry: "KeywordValidatorRegistry"):
super().__init__(registry)

self.operation_ids_registry: Optional[List[str]] = []
self.operation_ids_registry: Optional[list[str]] = []

@property
def responses_validator(self) -> ResponsesValidator:
Expand Down Expand Up @@ -356,8 +356,7 @@ def __call__(
for path in self._get_path_params_from_url(url):
if path not in all_params:
yield UnresolvableParameterError(
"Path parameter '{}' for '{}' operation in '{}' "
"was not resolved".format(path, name, url)
f"Path parameter '{path}' for '{name}' operation in '{url}' was not resolved"
)
return

Expand Down
2 changes: 1 addition & 1 deletion openapi_spec_validator/validation/protocols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterator
from collections.abc import Iterator
from typing import Optional
from typing import Protocol
from typing import runtime_checkable
Expand Down
6 changes: 3 additions & 3 deletions openapi_spec_validator/validation/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import warnings
from collections.abc import Hashable
from typing import Any
from typing import Iterator
from typing import Mapping
from collections.abc import Iterator
from collections.abc import Mapping
from typing import Optional
from typing import Tuple

Expand Down Expand Up @@ -59,7 +59,7 @@ def iter_errors(


class DetectValidatorProxy:
def __init__(self, choices: Mapping[Tuple[str, str], SpecValidatorProxy]):
def __init__(self, choices: Mapping[tuple[str, str], SpecValidatorProxy]):
self.choices = choices

def detect(self, instance: Schema) -> SpecValidatorProxy:
Expand Down
4 changes: 2 additions & 2 deletions openapi_spec_validator/validation/registries.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from __future__ import annotations

from typing import DefaultDict
from typing import Mapping
from collections.abc import Mapping
from typing import Type

from openapi_spec_validator.validation.keywords import KeywordValidator


class KeywordValidatorRegistry(DefaultDict[str, KeywordValidator]):
def __init__(
self, keyword_validators: Mapping[str, Type[KeywordValidator]]
self, keyword_validators: Mapping[str, type[KeywordValidator]]
):
super().__init__()
self.keyword_validators = keyword_validators
Expand Down
2 changes: 1 addition & 1 deletion openapi_spec_validator/validation/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from openapi_spec_validator.validation.validators import SpecValidator

SpecValidatorType = Type[SpecValidator]
SpecValidatorType = type[SpecValidator]
8 changes: 4 additions & 4 deletions openapi_spec_validator/validation/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging
import warnings
from functools import lru_cache
from typing import Iterator
from collections.abc import Iterator
from typing import List
from typing import Mapping
from collections.abc import Mapping
from typing import Optional
from typing import Type
from typing import cast
Expand All @@ -31,10 +31,10 @@

class SpecValidator:
resolver_handlers = default_handlers
keyword_validators: Mapping[str, Type[keywords.KeywordValidator]] = {
keyword_validators: Mapping[str, type[keywords.KeywordValidator]] = {
"__root__": keywords.RootValidator,
}
root_keywords: List[str] = []
root_keywords: list[str] = []
schema_validator: Validator = NotImplemented

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion openapi_spec_validator/versions/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
minor="1",
)

VERSIONS: List[SpecVersion] = [OPENAPIV2, OPENAPIV30, OPENAPIV31]
VERSIONS: list[SpecVersion] = [OPENAPIV2, OPENAPIV30, OPENAPIV31]
2 changes: 1 addition & 1 deletion openapi_spec_validator/versions/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class SpecVersionFinder:
pattern = compile(r"(?P<major>\d+)\.(?P<minor>\d+)(\..*)?")

def __init__(self, versions: List[SpecVersion]) -> None:
def __init__(self, versions: list[SpecVersion]) -> None:
self.versions = versions

def find(self, spec: Schema) -> SpecVersion:
Expand Down