Skip to content

Commit

Permalink
Run pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Jan 12, 2025
1 parent 187e5d8 commit c6b4951
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 56 deletions.
4 changes: 2 additions & 2 deletions sanic_ext/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import os

from types import SimpleNamespace
from typing import Any, Callable, Dict, List, Optional, Type, Union
from collections.abc import Mapping
from types import SimpleNamespace
from typing import Any, Callable, Optional, Union
from warnings import warn

from sanic import Sanic, __version__
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import os

from typing import Any, Dict, List, Optional, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from sanic import Sanic
from sanic.config import Config as SanicConfig
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any, Dict, Type, Union
from typing import Any, Union

from sanic.app import Sanic
from sanic.exceptions import SanicException
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/http/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from datetime import timedelta
from types import SimpleNamespace
from typing import Any, FrozenSet, List, Optional, Tuple, Union
from typing import Any, Optional, Union

from sanic import HTTPResponse, Request, Sanic
from sanic.exceptions import SanicException
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/http/methods.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections.abc import Sequence
from functools import partial
from inspect import isawaitable
from operator import itemgetter
from typing import Union
from collections.abc import Sequence

from sanic import Sanic
from sanic.constants import HTTPMethod
Expand Down
4 changes: 0 additions & 4 deletions sanic_ext/extensions/injection/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
TYPE_CHECKING,
Any,
Callable,
Dict,
Optional,
Set,
Tuple,
Type,
get_args,
get_type_hints,
)
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/injection/injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import partial
from inspect import getmembers, isclass, isfunction
from typing import Any, Callable, Dict, Optional, Tuple, Type, get_type_hints
from typing import Any, Callable, Optional, get_type_hints

from sanic import Sanic
from sanic.constants import HTTP_METHODS
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/injection/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Callable, Dict, Optional, Set, Tuple, Type
from typing import Any, Callable, Optional

from sanic.app import Sanic
from sanic.config import Config
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/logging/extractor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from typing import Any, Dict, Optional, TypedDict
from typing import Any, Optional, TypedDict


class LoggerConfig(TypedDict):
Expand Down
1 change: 0 additions & 1 deletion sanic_ext/extensions/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from queue import Empty, Full
from signal import SIGINT, SIGTERM
from signal import signal as signal_func
from typing import List

from sanic import Sanic
from sanic.log import logger as root_logger
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/openapi/builders.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

from collections import defaultdict
from typing import TYPE_CHECKING, Optional, Union, cast
from collections.abc import Sequence
from typing import TYPE_CHECKING, Optional, Union, cast

from sanic_ext.extensions.openapi.constants import (
SecuritySchemeAuthorization,
Expand Down
3 changes: 0 additions & 3 deletions sanic_ext/extensions/openapi/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
from inspect import isclass
from typing import (
Any,
Dict,
List,
Literal,
Optional,
Type,
Union,
get_type_hints,
)
Expand Down
5 changes: 1 addition & 4 deletions sanic_ext/extensions/openapi/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
"""

from collections.abc import Sequence
from functools import wraps
from inspect import isawaitable, isclass
from typing import (
Any,
Callable,
Dict,
List,
Literal,
Optional,
Type,
TypeVar,
Union,
overload,
)
from collections.abc import Sequence

from sanic import Blueprint
from sanic.exceptions import InvalidUsage, SanicException
Expand Down
2 changes: 0 additions & 2 deletions sanic_ext/extensions/openapi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from inspect import getmembers, isclass, isfunction, ismethod
from typing import (
Any,
Dict,
List,
Optional,
Union,
get_args,
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/templating/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import wraps
from inspect import isawaitable
from typing import TYPE_CHECKING, Dict, Optional, Union
from typing import TYPE_CHECKING, Optional, Union

from jinja2 import Environment
from sanic.compat import Header
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/templating/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os

from collections import abc
from collections.abc import Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Union
from collections.abc import Sequence

from jinja2 import (
Environment,
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/templating/render.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from inspect import isawaitable
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
from typing import TYPE_CHECKING, Any, Optional, Union

from sanic import Sanic
from sanic.compat import Header
Expand Down
38 changes: 16 additions & 22 deletions sanic_ext/extras/validation/check.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from __future__ import annotations

from collections.abc import Mapping
from dataclasses import _HAS_DEFAULT_FACTORY # type: ignore
from typing import (
Any,
Literal,
NamedTuple,
Optional,
Tuple,
Union,
get_args,
get_origin,
)
from collections.abc import Mapping

from sanic_ext.utils.typing import (
UnionType,
Expand Down Expand Up @@ -54,9 +53,7 @@ class Hint(NamedTuple):
allowed: tuple[Hint, ...] # type: ignore
allow_missing: bool

def validate(
self, value, schema, allow_multiple=False, allow_coerce=False
):
def validate(self, value, schema, allow_multiple=False, allow_coerce=False):
if not self.typed:
if self.model:
return check_data(
Expand Down Expand Up @@ -188,11 +185,16 @@ def check_data(model, data, schema, allow_multiple=False, allow_coerce=False):

if MSGSPEC and is_msgspec(model):
try:
return msgspec.from_builtins(
hydration_values, model, str_values=True, str_keys=True
)
except msgspec.ValidationError as e:
raise TypeError(e)
try:
return msgspec.to_builtins(hydration_values, str_keys=True)
except msgspec.ValidationError as e:
raise TypeError(e)
except AttributeError:
try:
return msgspec.convert(hydration_values, model, str_keys=True)
except msgspec.ValidationError as e:
raise TypeError(e)

else:
return model(**hydration_values)

Expand All @@ -213,18 +215,14 @@ def _check_types(value, literal, expected):
raise ValueError(f"Value '{value}' is not of type {expected}")


def _check_nullability(
value, nullable, allowed, schema, allow_multiple, allow_coerce
):
def _check_nullability(value, nullable, allowed, schema, allow_multiple, allow_coerce):
if not nullable and value is None:
raise ValueError("Value cannot be None")
if nullable and value is not None:
exc = None
for hint in allowed:
try:
value = hint.validate(
value, schema, allow_multiple, allow_coerce
)
value = hint.validate(value, schema, allow_multiple, allow_coerce)
except ValueError as e:
exc = e
else:
Expand All @@ -234,9 +232,7 @@ def _check_nullability(
if len(allowed) == 1:
raise exc
else:
options = ", ".join(
[str(option.hint) for option in allowed]
)
options = ", ".join([str(option.hint) for option in allowed])
raise ValueError(
f"Value '{value}' must be one of {options}, or None"
)
Expand All @@ -258,9 +254,7 @@ def _check_list(value, allowed, hint, schema, allow_multiple, allow_coerce):
if isinstance(value, list):
try:
return [
_check_inclusion(
item, allowed, schema, allow_multiple, allow_coerce
)
_check_inclusion(item, allowed, schema, allow_multiple, allow_coerce)
for item in value
]
except (ValueError, TypeError):
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extras/validation/clean.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Type, get_origin, get_type_hints
from typing import Any, get_origin, get_type_hints


def clean_data(model: type[object], data: dict[str, Any]) -> dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extras/validation/decorator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import wraps
from inspect import isawaitable
from typing import Callable, Optional, Type, TypeVar, Union
from typing import Callable, Optional, TypeVar, Union

from sanic import Request

Expand Down
2 changes: 0 additions & 2 deletions sanic_ext/extras/validation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from inspect import isclass, signature
from typing import (
Any,
Dict,
Literal,
Optional,
Tuple,
Union,
get_args,
get_origin,
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extras/validation/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, Tuple, Type
from typing import Any, Callable

from sanic_ext.exceptions import ValidationError

Expand Down
2 changes: 0 additions & 2 deletions sanic_ext/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import re

from typing import Tuple


# Expression from https://github.com/pypa/packaging
VERSION_PATTERN = r"""
Expand Down

0 comments on commit c6b4951

Please sign in to comment.