Skip to content

Commit c6b4951

Browse files
committed
Run pretty
1 parent 187e5d8 commit c6b4951

23 files changed

+33
-56
lines changed

sanic_ext/bootstrap.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import os
44

5-
from types import SimpleNamespace
6-
from typing import Any, Callable, Dict, List, Optional, Type, Union
75
from collections.abc import Mapping
6+
from types import SimpleNamespace
7+
from typing import Any, Callable, Optional, Union
88
from warnings import warn
99

1010
from sanic import Sanic, __version__

sanic_ext/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import os
44

5-
from typing import Any, Dict, List, Optional, Union
65
from collections.abc import Sequence
6+
from typing import Any, Optional, Union
77

88
from sanic import Sanic
99
from sanic.config import Config as SanicConfig

sanic_ext/extensions/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from abc import ABC, abstractmethod
4-
from typing import Any, Dict, Type, Union
4+
from typing import Any, Union
55

66
from sanic.app import Sanic
77
from sanic.exceptions import SanicException

sanic_ext/extensions/http/cors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
from datetime import timedelta
55
from types import SimpleNamespace
6-
from typing import Any, FrozenSet, List, Optional, Tuple, Union
6+
from typing import Any, Optional, Union
77

88
from sanic import HTTPResponse, Request, Sanic
99
from sanic.exceptions import SanicException

sanic_ext/extensions/http/methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from collections.abc import Sequence
12
from functools import partial
23
from inspect import isawaitable
34
from operator import itemgetter
45
from typing import Union
5-
from collections.abc import Sequence
66

77
from sanic import Sanic
88
from sanic.constants import HTTPMethod

sanic_ext/extensions/injection/constructor.py

-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
TYPE_CHECKING,
77
Any,
88
Callable,
9-
Dict,
109
Optional,
11-
Set,
12-
Tuple,
13-
Type,
1410
get_args,
1511
get_type_hints,
1612
)

sanic_ext/extensions/injection/injector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from functools import partial
44
from inspect import getmembers, isclass, isfunction
5-
from typing import Any, Callable, Dict, Optional, Tuple, Type, get_type_hints
5+
from typing import Any, Callable, Optional, get_type_hints
66

77
from sanic import Sanic
88
from sanic.constants import HTTP_METHODS

sanic_ext/extensions/injection/registry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, Callable, Dict, Optional, Set, Tuple, Type
3+
from typing import Any, Callable, Optional
44

55
from sanic.app import Sanic
66
from sanic.config import Config

sanic_ext/extensions/logging/extractor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from typing import Any, Dict, Optional, TypedDict
3+
from typing import Any, Optional, TypedDict
44

55

66
class LoggerConfig(TypedDict):

sanic_ext/extensions/logging/logger.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from queue import Empty, Full
88
from signal import SIGINT, SIGTERM
99
from signal import signal as signal_func
10-
from typing import List
1110

1211
from sanic import Sanic
1312
from sanic.log import logger as root_logger

sanic_ext/extensions/openapi/builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

33
from collections import defaultdict
4-
from typing import TYPE_CHECKING, Optional, Union, cast
54
from collections.abc import Sequence
5+
from typing import TYPE_CHECKING, Optional, Union, cast
66

77
from sanic_ext.extensions.openapi.constants import (
88
SecuritySchemeAuthorization,

sanic_ext/extensions/openapi/definitions.py

-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
from inspect import isclass
1111
from typing import (
1212
Any,
13-
Dict,
14-
List,
1513
Literal,
1614
Optional,
17-
Type,
1815
Union,
1916
get_type_hints,
2017
)

sanic_ext/extensions/openapi/openapi.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
55
"""
66

7+
from collections.abc import Sequence
78
from functools import wraps
89
from inspect import isawaitable, isclass
910
from typing import (
1011
Any,
1112
Callable,
12-
Dict,
13-
List,
1413
Literal,
1514
Optional,
16-
Type,
1715
TypeVar,
1816
Union,
1917
overload,
2018
)
21-
from collections.abc import Sequence
2219

2320
from sanic import Blueprint
2421
from sanic.exceptions import InvalidUsage, SanicException

sanic_ext/extensions/openapi/types.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from inspect import getmembers, isclass, isfunction, ismethod
88
from typing import (
99
Any,
10-
Dict,
11-
List,
1210
Optional,
1311
Union,
1412
get_args,

sanic_ext/extensions/templating/engine.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from functools import wraps
44
from inspect import isawaitable
5-
from typing import TYPE_CHECKING, Dict, Optional, Union
5+
from typing import TYPE_CHECKING, Optional, Union
66

77
from jinja2 import Environment
88
from sanic.compat import Header

sanic_ext/extensions/templating/extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44

55
from collections import abc
6+
from collections.abc import Sequence
67
from pathlib import Path
78
from typing import TYPE_CHECKING, Union
8-
from collections.abc import Sequence
99

1010
from jinja2 import (
1111
Environment,

sanic_ext/extensions/templating/render.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from inspect import isawaitable
4-
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
4+
from typing import TYPE_CHECKING, Any, Optional, Union
55

66
from sanic import Sanic
77
from sanic.compat import Header

sanic_ext/extras/validation/check.py

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from __future__ import annotations
22

3+
from collections.abc import Mapping
34
from dataclasses import _HAS_DEFAULT_FACTORY # type: ignore
45
from typing import (
56
Any,
67
Literal,
78
NamedTuple,
89
Optional,
9-
Tuple,
1010
Union,
1111
get_args,
1212
get_origin,
1313
)
14-
from collections.abc import Mapping
1514

1615
from sanic_ext.utils.typing import (
1716
UnionType,
@@ -54,9 +53,7 @@ class Hint(NamedTuple):
5453
allowed: tuple[Hint, ...] # type: ignore
5554
allow_missing: bool
5655

57-
def validate(
58-
self, value, schema, allow_multiple=False, allow_coerce=False
59-
):
56+
def validate(self, value, schema, allow_multiple=False, allow_coerce=False):
6057
if not self.typed:
6158
if self.model:
6259
return check_data(
@@ -188,11 +185,16 @@ def check_data(model, data, schema, allow_multiple=False, allow_coerce=False):
188185

189186
if MSGSPEC and is_msgspec(model):
190187
try:
191-
return msgspec.from_builtins(
192-
hydration_values, model, str_values=True, str_keys=True
193-
)
194-
except msgspec.ValidationError as e:
195-
raise TypeError(e)
188+
try:
189+
return msgspec.to_builtins(hydration_values, str_keys=True)
190+
except msgspec.ValidationError as e:
191+
raise TypeError(e)
192+
except AttributeError:
193+
try:
194+
return msgspec.convert(hydration_values, model, str_keys=True)
195+
except msgspec.ValidationError as e:
196+
raise TypeError(e)
197+
196198
else:
197199
return model(**hydration_values)
198200

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

215217

216-
def _check_nullability(
217-
value, nullable, allowed, schema, allow_multiple, allow_coerce
218-
):
218+
def _check_nullability(value, nullable, allowed, schema, allow_multiple, allow_coerce):
219219
if not nullable and value is None:
220220
raise ValueError("Value cannot be None")
221221
if nullable and value is not None:
222222
exc = None
223223
for hint in allowed:
224224
try:
225-
value = hint.validate(
226-
value, schema, allow_multiple, allow_coerce
227-
)
225+
value = hint.validate(value, schema, allow_multiple, allow_coerce)
228226
except ValueError as e:
229227
exc = e
230228
else:
@@ -234,9 +232,7 @@ def _check_nullability(
234232
if len(allowed) == 1:
235233
raise exc
236234
else:
237-
options = ", ".join(
238-
[str(option.hint) for option in allowed]
239-
)
235+
options = ", ".join([str(option.hint) for option in allowed])
240236
raise ValueError(
241237
f"Value '{value}' must be one of {options}, or None"
242238
)
@@ -258,9 +254,7 @@ def _check_list(value, allowed, hint, schema, allow_multiple, allow_coerce):
258254
if isinstance(value, list):
259255
try:
260256
return [
261-
_check_inclusion(
262-
item, allowed, schema, allow_multiple, allow_coerce
263-
)
257+
_check_inclusion(item, allowed, schema, allow_multiple, allow_coerce)
264258
for item in value
265259
]
266260
except (ValueError, TypeError):

sanic_ext/extras/validation/clean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Type, get_origin, get_type_hints
1+
from typing import Any, get_origin, get_type_hints
22

33

44
def clean_data(model: type[object], data: dict[str, Any]) -> dict[str, Any]:

sanic_ext/extras/validation/decorator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from functools import wraps
22
from inspect import isawaitable
3-
from typing import Callable, Optional, Type, TypeVar, Union
3+
from typing import Callable, Optional, TypeVar, Union
44

55
from sanic import Request
66

sanic_ext/extras/validation/schema.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
from inspect import isclass, signature
55
from typing import (
66
Any,
7-
Dict,
87
Literal,
98
Optional,
10-
Tuple,
119
Union,
1210
get_args,
1311
get_origin,

sanic_ext/extras/validation/validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable, Dict, Tuple, Type
1+
from typing import Any, Callable
22

33
from sanic_ext.exceptions import ValidationError
44

sanic_ext/utils/version.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import re
22

3-
from typing import Tuple
4-
53

64
# Expression from https://github.com/pypa/packaging
75
VERSION_PATTERN = r"""

0 commit comments

Comments
 (0)