Skip to content

Commit

Permalink
Make TypeAdapter's typing compatible with special forms (#8923)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Feb 29, 2024
1 parent 4b31fd7 commit 575f473
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pydantic/type_adapter.py
Expand Up @@ -126,7 +126,7 @@ class TypeAdapter(Generic[T]):

@overload
def __init__(
self,
self: TypeAdapter[T],
type: type[T],
*,
config: ConfigDict | None = ...,
Expand All @@ -135,12 +135,13 @@ def __init__(
) -> None:
...

# This second overload is for unsupported special forms (such as Union). `pyright` handles them fine, but `mypy` does not match
# them against `type: type[T]`, so an explicit overload with `type: T` is needed.
# This second overload is for unsupported special forms (such as Annotated, Union, etc.)
# Currently there is no way to type this correctly
# See https://github.com/python/typing/pull/1618
@overload
def __init__( # pyright: ignore[reportOverlappingOverload]
self,
type: T,
def __init__(
self: TypeAdapter[Any],
type: Any,
*,
config: ConfigDict | None = ...,
_parent_depth: int = ...,
Expand All @@ -150,7 +151,7 @@ def __init__( # pyright: ignore[reportOverlappingOverload]

def __init__(
self,
type: type[T] | T,
type: Any,
*,
config: ConfigDict | None = None,
_parent_depth: int = 2,
Expand Down

0 comments on commit 575f473

Please sign in to comment.