Backtestspydanticrun-20260930-144322#8998

Issue #8998 Merged fix PR #13459 Run 30 Sep 2026 · run-20260930-144322 pydantic/pydantic

Missing type for PEP695 TypeAliasType vs TypeAlias when using TypeAdapter

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Patch B fixes the reported problem directly. It inserts a `TypeForm[T]` overload between the existing `type[T]` overload and the `Any` fallback on `TypeAdapter.__init__`. A `TypeAliasType` / PEP 695 alias is not a `type[...]`, so it now resolves through `TypeForm[T]` to the aliased type instead of `TypeAliasType`. Keeping the `Any` fallback means type checkers without PEP 747 support behave exactly as before, so nothing regresses. Its tests target the issue itself: `TypeAliasType('MyList', list[dict[str, list[int]]])` and a `TypeAlias` equivalent, with `assert_type` on both the adapter and the `validate_python` result. It also removes the now-unneeded pyright ignores on `Annotated` and the union. The change is small, focused and consistent with the surrounding overload style.

Patch A is a broad migration to `TypeForm` across the codebase. It touches fields, serializers, pipeline, `create_model`, `ValidateAs` and `__class_getitem__`, adds pyrefly config and ignores to many test files, and pins the pyright version in CI. It also collapses `TypeAdapter.__init__` to a single `TypeForm[T]` signature with no `Any` fallback. That makes checkers lacking `TypeForm` support error on inputs such as `MISSING`, which its own tests acknowledge by adding mypy and pyrefly ignores. That is a user-facing regression risk. It also removes `| None` from `_FromFieldInfoInputs.annotation`, adds several `pyright: ignore` workarounds, and removes a mypy-compatibility doc tip. Despite all this churn, it never tests the actual scenario in the issue (a PEP 695 / `TypeAliasType` alias).

Patch B resolves the issue with less risk and better-targeted tests.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

4m 54s31 turns

Wall-clock time in the container

Full test suite

No new failures

12,615 passed · 509 skipped · 13,124 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

42vs 273 merged

Changed lines, ours vs merged

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

There seems to be a difference between the type that is returned from TypeAdapter when used on a PEP695 TypeAliasType compared to when it is used on a TypeAlias. See example below. When TypeAdapter is used on a TypeAlias, the correct type is shown. However, when the TypeAliasType is used, the type is shown as TypeAliasType. This causes the type-checker to see red.

Example Code

from typing import TypeAlias, reveal_type

from pydantic import TypeAdapter

my_type_alias: TypeAlias = list[dict[str, list[int]]]
x: my_type_alias = [{"a": [1, 2, 3]}]

res = TypeAdapter(type=my_type_alias).validate_python(x)
reveal_type(res)  # type of res is "list[dict[str, list[int]]]"


type my_type = list[dict[str, list[int]]]
x: my_type = [{"a": [1, 2, 3]}]

res = TypeAdapter(type=my_type).validate_python(x)
reveal_type(res)  # type of res is "TypeAliasType"

Python, Pydantic & OS Version

pydantic version: 2.6.3
        pydantic-core version: 2.16.3
          pydantic-core build: profile=release pgo=true
                 install path: /usr/local/lib/python3.12/site-packages/pydantic
               python version: 3.12.2 (main, Feb 13 2024, 09:17:46) [GCC 12.2.0]
                     platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.36
             related packages: pyright-1.1.352 pyright-1.1.353 typing_extensions-4.10.0 pydantic-extra-types-2.6.0 fastapi-0.110.0 pydantic-settings-2.2.1
                       commit: unknown

The two patches

Our patch+33 −9
pydantic/type_adapter.pyindex 1c6824ac..74a575c9 100644@@ -18,7 +18,7 @@ from typing import ( )  from pydantic_core import CoreSchema, SchemaSerializer, SchemaValidator, Some-from typing_extensions import ParamSpec, is_typeddict+from typing_extensions import ParamSpec, TypeForm, is_typeddict  from pydantic.errors import PydanticUserError from pydantic.main import BaseModel, IncEx@@ -178,8 +178,19 @@ class TypeAdapter(Generic[T]):         module: str | None = ...,     ) -> None: ... -    # This second overload is for unsupported special forms (such as Annotated, Union, etc.)-    # Currently there is no way to type this correctly+    # This second overload is for special forms and type aliases (such as PEP 695 `type` statements /+    # `TypeAliasType`, `Annotated`, unions, etc.), for type checkers supporting PEP 747 (`TypeForm`).+    @overload+    def __init__(+        self,+        type: TypeForm[T],+        *,+        config: ConfigDict | None = ...,+        _parent_depth: int = ...,+        module: str | None = ...,+    ) -> None: ...++    # This third overload is a fallback for type checkers that don't support PEP 747 (`TypeForm`).     # See https://github.com/python/typing/pull/1618     @overload     def __init__(tests/typechecking/type_adapter.pyindex 042b1c52..40c58229 100644@@ -1,8 +1,8 @@-# to be removed with PEP 747:+# to be removed once mypy supports PEP 747 (`TypeForm`): # mypy: disable_error_code=var-annotated-from typing import Annotated+from typing import Annotated, TypeAlias -from typing_extensions import assert_type+from typing_extensions import TypeAliasType, assert_type  from pydantic import TypeAdapter @@ -15,13 +15,26 @@ ta1.dump_python('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgument ta1.dump_json(1) ta1.dump_json('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType] -# The following use cases require PEP 747: TypeExpr:+# The following use cases require PEP 747 (`TypeForm`) support from the type checker+# (mypy does not infer unions yet):  ta2 = TypeAdapter(Annotated[int, ...])-assert_type(ta2, TypeAdapter[int])  # type: ignore[assert-type]  # pyright: ignore[reportAssertTypeFailure]+assert_type(ta2, TypeAdapter[int])  ta3: TypeAdapter[int] = TypeAdapter(Annotated[int, ...]) assert_type(ta3, TypeAdapter[int])  ta4 = TypeAdapter(int | str)-assert_type(ta4, TypeAdapter[int | str])  # type: ignore[assert-type]  # pyright: ignore[reportAssertTypeFailure]+assert_type(ta4, TypeAdapter[int | str])  # type: ignore[assert-type]++# Type aliases (PEP 695 / `TypeAliasType` aliases were previously not inferred as the aliased type):++MyList = TypeAliasType('MyList', list[dict[str, list[int]]])+ta5 = TypeAdapter(MyList)+assert_type(ta5, TypeAdapter[list[dict[str, list[int]]]])  # pyrefly: ignore[assert-type]+assert_type(ta5.validate_python([{'a': [1]}]), list[dict[str, list[int]]])  # pyrefly: ignore[assert-type]++MyListAlias: TypeAlias = list[dict[str, list[int]]]+ta6 = TypeAdapter(MyListAlias)+assert_type(ta6, TypeAdapter[list[dict[str, list[int]]]])+assert_type(ta6.validate_python([{'a': [1]}]), list[dict[str, list[int]]]) 
Merged fix · PR #13459+136 −137
.github/workflows/ci.ymlindex 2170a2eef..ce4bdd8ce 100644@@ -796,6 +796,9 @@ jobs:        - name: Run typechecking integration tests (Pyright)         run: make test-typechecking-pyright+        env:+          # Until we get https://github.com/RobertCraigie/pyright-python/pull/365:+          PYRIGHT_PYTHON_FORCE_VERSION: '1.1.413'        - name: Run typechecking integration tests (Mypy)         run: make test-typechecking-mypyMakefileindex 64707cdcd..c563a7620 100644@@ -68,7 +68,7 @@ test-typechecking-mypy: .uv  .PHONY: test-typechecking-pyrefly  ## Typechecking integration tests (Pyrefly). test-typechecking-pyrefly: .uv-	uv run bash -c 'cd tests/typechecking && pyrefly --version && pyrefly check'+	uv run bash -c 'cd tests/typechecking && pyrefly --version && pyrefly check --config pyproject.toml'  .PHONY: test  ## Run all tests, skipping the type-checker integration tests test: .uvpydantic/_internal/_decorators.pyindex a7bc6dfa3..160a18c00 100644@@ -13,7 +13,7 @@ from itertools import islice from typing import TYPE_CHECKING, Any, ClassVar, Generic, Literal, TypeAlias, TypeVar  from pydantic_core import PydanticUndefined, PydanticUndefinedType, core_schema-from typing_extensions import Self, is_typeddict+from typing_extensions import Self, TypeForm, is_typeddict  from ..errors import PydanticUserError from . import _type_refs@@ -106,7 +106,7 @@ class FieldSerializerDecoratorInfo:     decorator_repr: ClassVar[str] = '@field_serializer'     fields: tuple[str, ...]     mode: Literal['plain', 'wrap']-    return_type: Any+    return_type: TypeForm[Any]     when_used: core_schema.WhenUsed     check_fields: bool | None @@ -126,7 +126,7 @@ class ModelSerializerDecoratorInfo:      decorator_repr: ClassVar[str] = '@model_serializer'     mode: Literal['plain', 'wrap']-    return_type: Any+    return_type: TypeForm[Any]     when_used: core_schema.WhenUsed  pydantic/_internal/_fields.pyindex 94477dfa2..29cde2dff 100644@@ -11,7 +11,7 @@ from re import Pattern from typing import TYPE_CHECKING, Any, TypeVar, cast  from pydantic_core import PydanticUndefined-from typing_extensions import TypeIs, get_args, get_origin  # noqa: UP035 (for `get_args` and `get_origin`)+from typing_extensions import TypeForm, TypeIs, get_args, get_origin  # noqa: UP035 (for `get_args` and `get_origin`) from typing_inspection import typing_objects from typing_inspection.introspection import AnnotationSource @@ -44,8 +44,7 @@ class PydanticMetadata(Representation):  @dataclasses.dataclass(slots=True, kw_only=True) class PydanticExtraInfo:-    # TODO: make use of PEP 747:-    annotation: Any+    annotation: TypeForm[Any]     complete: bool  pydantic/experimental/pipeline.pyindex 0fe407334..2eb8b94b2 100644@@ -14,6 +14,7 @@ from types import EllipsisType from typing import TYPE_CHECKING, Annotated, Any, Generic, Protocol, TypeAlias, TypeVar, overload  import annotated_types+from typing_extensions import TypeForm  if TYPE_CHECKING:     from pydantic import GetCoreSchemaHandler@@ -28,16 +29,16 @@ __all__ = ['validate_as', 'validate_as_deferred', 'transform']  @dataclass(frozen=True, slots=True) class _ValidateAs:-    tp: type[Any]+    tp: TypeForm[Any]     strict: bool = False   @dataclass class _ValidateAsDefer:-    func: Callable[[], type[Any]]+    func: Callable[[], TypeForm[Any]]      @cached_property-    def tp(self) -> type[Any]:+    def tp(self) -> TypeForm[Any]:         return self.func()  @@ -138,7 +139,7 @@ class _Pipeline(Generic[_InT, _OutT]):         return _Pipeline[_InT, _NewOutT](self._steps + (_Transform(func),))      @overload-    def validate_as(self, tp: type[_NewOutT], *, strict: bool = False) -> _Pipeline[_InT, _NewOutT]: ...+    def validate_as(self, tp: TypeForm[_NewOutT], *, strict: bool = False) -> _Pipeline[_InT, _NewOutT]: ...      @overload     def validate_as(@@ -148,12 +149,7 @@ class _Pipeline(Generic[_InT, _OutT]):         strict: bool = False,     ) -> _Pipeline[_InT, Any]: ... -    # TODO PEP 747: use TypeForm to properly type Annotated aliases (e.g. NewPath, FilePath).-    # This fallback accepts any type expression but loses generic type inference.-    @overload-    def validate_as(self, tp: Any, *, strict: bool = ...) -> _Pipeline[_InT, Any]: ...--    def validate_as(self, tp: type[_NewOutT] | EllipsisType | Any, *, strict: bool = False) -> _Pipeline[_InT, Any]:  # type: ignore+    def validate_as(self, tp: TypeForm[_NewOutT] | EllipsisType, *, strict: bool = False) -> _Pipeline[_InT, Any]:  # type: ignore         """Validate / parse the input into a new type.          If no type is provided, the type of the field is used.@@ -439,7 +435,7 @@ def _apply_step(step: _Step, s: cs.CoreSchema | None, handler: GetCoreSchemaHand  def _apply_parse(     s: cs.CoreSchema | None,-    tp: type[Any],+    tp: TypeForm[Any],     strict: bool,     handler: GetCoreSchemaHandler,     source_type: Any,pydantic/fields.pyindex 5149a1823..4d9d4dce9 100644@@ -17,7 +17,7 @@ from warnings import warn import annotated_types import typing_extensions from pydantic_core import MISSING, PydanticUndefined-from typing_extensions import Self, TypedDict, Unpack, deprecated+from typing_extensions import Self, TypedDict, TypeForm, Unpack, deprecated from typing_inspection import typing_objects from typing_inspection.introspection import UNKNOWN, AnnotationSource, ForbiddenQualifier, Qualifier, inspect_annotation @@ -51,8 +51,7 @@ else: class _FromFieldInfoInputs(TypedDict, total=False):     """This class exists solely to add type checking for the `**kwargs` in `FieldInfo.from_field`.""" -    # TODO PEP 747: use TypeForm:-    annotation: type[Any] | None+    annotation: TypeForm[Any]     default_factory: Callable[[], Any] | Callable[[dict[str, Any]], Any] | None     alias: str | None     alias_priority: int | None@@ -91,8 +90,7 @@ class _FromFieldInfoInputs(TypedDict, total=False):   class _FieldInfoAsDict(TypedDict, closed=True):-    # TODO PEP 747: use TypeForm:-    annotation: Any+    annotation: TypeForm[Any] | None     metadata: list[Any]     attributes: dict[str, Any] @@ -143,8 +141,7 @@ class FieldInfo(_repr.Representation):               (e.g. [custom types handlers](../concepts/types.md#as-an-annotation) or any object not recognized by Pydantic).     """ -    # TODO PEP 747: use TypeForm:-    annotation: type[Any] | None+    annotation: TypeForm[Any] | None     default: Any     default_factory: Callable[[], Any] | Callable[[dict[str, Any]], Any] | None     alias: str | None@@ -223,7 +220,7 @@ class FieldInfo(_repr.Representation):     def __init__(         self,         *,-        annotation: type[Any] | None = _Unset,+        annotation: TypeForm[Any] | None = _Unset,         default: Any = _Unset,         default_factory: Callable[[], Any] | Callable[[dict[str, Any]], Any] | None = _Unset,         alias: str | None = _Unset,pydantic/functional_serializers.pyindex aad3a8b8d..f7ab51849 100644@@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Annotated, Any, Literal, TypeAlias, TypeVar, o  from pydantic_core import PydanticUndefined, core_schema from pydantic_core.core_schema import SerializationInfo, SerializerFunctionWrapHandler, WhenUsed+from typing_extensions import TypeForm  from . import PydanticUndefinedAnnotation from ._internal import _decorators@@ -48,7 +49,7 @@ class PlainSerializer:     """      func: core_schema.SerializerFunction-    return_type: Any = PydanticUndefined+    return_type: TypeForm[Any] = PydanticUndefined  # pyright: ignore[reportAssignmentType]     when_used: WhenUsed = 'always'      def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:@@ -142,7 +143,7 @@ class WrapSerializer:     """      func: core_schema.WrapSerializerFunction-    return_type: Any = PydanticUndefined+    return_type: TypeForm[Any] = PydanticUndefined  # pyright: ignore[reportAssignmentType]     when_used: WhenUsed = 'always'      def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:@@ -202,7 +203,7 @@ def field_serializer(     /,     *fields: str,     mode: Literal['wrap'],-    return_type: Any = ...,+    return_type: TypeForm[Any] = ...,     when_used: WhenUsed = ...,     check_fields: bool | None = ..., ) -> Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT]: ...@@ -214,7 +215,7 @@ def field_serializer(     /,     *fields: str,     mode: Literal['plain'] = ...,-    return_type: Any = ...,+    return_type: TypeForm[Any] = ...,     when_used: WhenUsed = ...,     check_fields: bool | None = ..., ) -> Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT]: ...@@ -225,8 +226,7 @@ def field_serializer(  # noqa: D417     /,     *fields: str,     mode: Literal['plain', 'wrap'] = 'plain',-    # TODO PEP 747 (grep for 'return_type' on the whole code base):-    return_type: Any = PydanticUndefined,+    return_type: TypeForm[Any] = PydanticUndefined,  # pyright: ignore[reportArgumentType]     when_used: WhenUsed = 'always',     check_fields: bool | None = None, ) -> (@@ -339,7 +339,7 @@ def model_serializer(f: _ModelPlainSerializerT, /) -> _ModelPlainSerializerT: ..  @overload def model_serializer(-    *, mode: Literal['wrap'], when_used: WhenUsed = 'always', return_type: Any = ...+    *, mode: Literal['wrap'], when_used: WhenUsed = 'always', return_type: TypeForm[Any] = ... ) -> Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT]: ...  @@ -348,17 +348,17 @@ def model_serializer(     *,     mode: Literal['plain'] = ...,     when_used: WhenUsed = 'always',-    return_type: Any = ...,+    return_type: TypeForm[Any] = ..., ) -> Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]: ...  -def model_serializer(+def model_serializer(  # pyright: ignore[reportInconsistentOverload]     f: _ModelPlainSerializerT | _ModelWrapSerializerT | None = None,     /,     *,     mode: Literal['plain', 'wrap'] = 'plain',     when_used: WhenUsed = 'always',-    return_type: Any = PydanticUndefined,+    return_type: TypeForm[Any] = PydanticUndefined,  # pyright: ignore[reportArgumentType] ) -> (     _ModelPlainSerializerT     | Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT]pydantic/functional_validators.pyindex 339e89946..066c6e0aa 100644@@ -10,7 +10,7 @@ from functools import partialmethod from typing import TYPE_CHECKING, Annotated, Any, Literal, TypeAlias, TypeVar, cast, overload  from pydantic_core import PydanticUndefined, core_schema-from typing_extensions import Self+from typing_extensions import Self, TypeForm  from ._internal import _decorators, _generics from .annotated_handlers import GetCoreSchemaHandler@@ -892,8 +892,7 @@ class ValidateAs:         ```     """ -    # TODO: make use of PEP 747-    def __init__(self, from_type: type[_FromTypeT], /, instantiation_hook: Callable[[_FromTypeT], Any]) -> None:+    def __init__(self, from_type: TypeForm[_FromTypeT], /, instantiation_hook: Callable[[_FromTypeT], Any]) -> None:         self.from_type = from_type         self.instantiation_hook = instantiation_hook pydantic/main.pyindex be444fa7b..1c0258c69 100644@@ -31,7 +31,7 @@ from typing import ( import pydantic_core import typing_extensions from pydantic_core import PydanticUndefined, ValidationError-from typing_extensions import Self, Sentinel, TypeAlias, Unpack+from typing_extensions import Self, Sentinel, TypeAlias, TypeForm, Unpack  from . import PydanticDeprecatedSince20, PydanticDeprecatedSince211 from ._internal import (@@ -643,7 +643,7 @@ class BaseModel(metaclass=_model_construction.ModelMetaclass):         )      @classmethod-    def model_parametrized_name(cls, params: tuple[type[Any], ...]) -> str:+    def model_parametrized_name(cls, params: tuple[TypeForm[Any], ...]) -> str:         """Compute the class name for parametrizations of generic classes.          This method can be overridden to achieve a custom naming scheme for generic BaseModels.@@ -969,7 +969,7 @@ class BaseModel(metaclass=_model_construction.ModelMetaclass):         """      def __class_getitem__(-        cls, typevar_values: type[Any] | tuple[type[Any], ...]+        cls, typevar_values: TypeForm[Any] | tuple[TypeForm[Any], ...]     ) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef:         cached = _generics.get_cached_generic_type_early(cls, typevar_values)         if cached is not None:@@ -1779,7 +1779,7 @@ def create_model(     __validators__: dict[str, Callable[..., Any]] | None = None,     __cls_kwargs__: dict[str, Any] | None = None,     __qualname__: str | None = None,-    **field_definitions: Any | tuple[Any, Any],+    **field_definitions: TypeForm[Any] | tuple[TypeForm[Any], Any], ) -> type[BaseModel]: ...  @@ -1795,7 +1795,7 @@ def create_model(     __validators__: dict[str, Callable[..., Any]] | None = None,     __cls_kwargs__: dict[str, Any] | None = None,     __qualname__: str | None = None,-    **field_definitions: Any | tuple[Any, Any],+    **field_definitions: TypeForm[Any] | tuple[TypeForm[Any], Any], ) -> type[ModelT]: ...  @@ -1810,8 +1810,7 @@ def create_model(  # noqa: C901     __validators__: dict[str, Callable[..., Any]] | None = None,     __cls_kwargs__: dict[str, Any] | None = None,     __qualname__: str | None = None,-    # TODO PEP 747: replace `Any` by the TypeForm:-    **field_definitions: Any | tuple[Any, Any],+    **field_definitions: TypeForm[Any] | tuple[TypeForm[Any], Any], ) -> type[ModelT]:     """!!! abstract "Usage Documentation"         [Dynamic Model Creation](../concepts/models.md#dynamic-model-creation)pydantic/type_adapter.pyindex 1c6824acb..2bce1b638 100644@@ -14,11 +14,10 @@ from typing import (     TypeVar,     cast,     final,-    overload, )  from pydantic_core import CoreSchema, SchemaSerializer, SchemaValidator, Some-from typing_extensions import ParamSpec, is_typeddict+from typing_extensions import ParamSpec, TypeForm, is_typeddict  from pydantic.errors import PydanticUserError from pydantic.main import BaseModel, IncEx@@ -105,16 +104,6 @@ class TypeAdapter(Generic[T]):         serializer: The schema serializer for the type.         pydantic_complete: Whether the core schema for the type is successfully built. -    ??? tip "Compatibility with `mypy`"-        Depending on the type used, `mypy` might raise an error when instantiating a `TypeAdapter`. As a workaround, you can explicitly-        annotate your variable:--        ```py-        from pydantic import TypeAdapter--        ta: TypeAdapter[str | int] = TypeAdapter(str | int)  # type: ignore[arg-type]-        ```-     ??? info "Namespace management nuances and implementation details"          Here, we collect some notes on namespace management, and subtle differences from `BaseModel`:@@ -168,32 +157,9 @@ class TypeAdapter(Generic[T]):     serializer: SchemaSerializer     pydantic_complete: bool -    @overload-    def __init__(-        self,-        type: type[T],-        *,-        config: ConfigDict | None = ...,-        _parent_depth: int = ...,-        module: str | None = ...,-    ) -> None: ...--    # 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__(-        self,-        type: Any,-        *,-        config: ConfigDict | None = ...,-        _parent_depth: int = ...,-        module: str | None = ...,-    ) -> None: ...-     def __init__(         self,-        type: Any,+        type: TypeForm[T],         *,         config: ConfigDict | None = None,         _parent_depth: int = 2,tests/test_missing_sentinel.pyindex 8c6b8ef3a..526122426 100644@@ -33,8 +33,7 @@ def test_missing_sentinel_model() -> None: def test_missing_sentinel_type_adapter() -> None:     """Note that this usage isn't explicitly supported (and useless in practice).""" -    # TODO Remove annotation with PEP 747:-    ta: TypeAdapter[object] = TypeAdapter(MISSING)+    ta = TypeAdapter(MISSING)      assert ta.validate_python(MISSING) is MISSING tests/typechecking/base_model.pyindex dfea46991..d71275455 100644@@ -16,13 +16,13 @@ class MyModel(BaseModel):  m1 = MyModel(x='hello', y=[1, 2, 3]) -m2 = MyModel(x='hello')  # type: ignore[call-arg]  # pyright: ignore[reportCallIssue]+m2 = MyModel(x='hello')  # type: ignore[call-arg]  # pyright: ignore[reportCallIssue]  # pyrefly: ignore[missing-argument]  m3 = MyModel(x='hello', y=[1, '2', b'3'])  # type: ignore[list-item]  # pyright: ignore[reportArgumentType] -m1.z + 'not an int'  # type: ignore[operator]  # pyright: ignore[reportOperatorIssue]+m1.z + 'not an int'  # type: ignore[operator]  # pyright: ignore[reportOperatorIssue]  # pyrefly: ignore[unsupported-operation] -m1.foobar  # type: ignore[attr-defined]  # pyright: ignore[reportAttributeAccessIssue]+m1.foobar  # type: ignore[attr-defined]  # pyright: ignore[reportAttributeAccessIssue]  # pyrefly: ignore[missing-attribute]   class Knight(BaseModel):@@ -34,5 +34,5 @@ k = Knight()  # type: ignore[call-arg]  # pyright: ignore[reportCallIssue]  assert_type(Knight.model_fields, dict[str, FieldInfo]) assert_type(Knight.model_computed_fields, dict[str, ComputedFieldInfo])-assert_type(k.model_fields, dict[str, FieldInfo])  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]-assert_type(k.model_computed_fields, dict[str, ComputedFieldInfo])  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]+assert_type(k.model_fields, dict[str, FieldInfo])  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]  # pyrefly: ignore[deprecated]+assert_type(k.model_computed_fields, dict[str, ComputedFieldInfo])  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]  # pyrefly: ignore[deprecated]tests/typechecking/computed_field.pyindex c7e15f943..d188a210b 100644@@ -21,6 +21,6 @@ class Square(BaseModel):  sq = Square(side=10) y = 12.4 + sq.area-z = 'x' + sq.area  # type: ignore[operator]  # pyright: ignore[reportOperatorIssue]+z = 'x' + sq.area  # type: ignore[operator]  # pyright: ignore[reportOperatorIssue]  # pyrefly: ignore[unsupported-operation] y_cached = 12.4 + sq.area_cached-z_cached = 'x' + sq.area_cached  # type: ignore[operator]  # pyright: ignore[reportOperatorIssue]+z_cached = 'x' + sq.area_cached  # type: ignore[operator]  # pyright: ignore[reportOperatorIssue]  # pyrefly: ignore[unsupported-operation]tests/typechecking/decorators.pyindex 95f4f9752..8dfaef054 100644@@ -57,10 +57,10 @@ class BeforeModelValidator(BaseModel):   class WrapModelValidator(BaseModel):-    @model_validator(mode='wrap')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]+    @model_validator(mode='wrap')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type]     def no_classmethod(cls, value: Any, handler: ModelWrapValidatorHandler[Self]) -> Self: ... -    @model_validator(mode='wrap')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]+    @model_validator(mode='wrap')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type]     @classmethod     def no_handler(cls, value: Any) -> Self: ... @@ -94,7 +94,7 @@ class WrapModelValidator(BaseModel):  class AfterModelValidator(BaseModel):     # Mypy somehow reports "Cannot infer function type argument" here:-    @model_validator(mode='after')  # type:ignore[misc]  # pyright: ignore[reportArgumentType]+    @model_validator(mode='after')  # type:ignore[misc]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type]     def missing_return_value(self) -> None: ...      @model_validator(mode='after')@@ -121,7 +121,7 @@ class BeforeFieldValidator(BaseModel):     @classmethod     def valid_classmethod(cls, value: Any) -> Any: ... -    @field_validator('foo', mode='before')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]+    @field_validator('foo', mode='before')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-specialization]     @classmethod     def invalid_with_info(cls, value: Any, info: int) -> Any: ... @@ -147,7 +147,7 @@ class AfterFieldValidator(BaseModel):     @classmethod     def valid_classmethod_info(cls, value: Any, info: ValidationInfo[int]) -> Any: ... -    @field_validator('foo', mode='after', json_schema_input_type=int)  # type: ignore[call-overload]  # pyright: ignore[reportCallIssue, reportArgumentType]+    @field_validator('foo', mode='after', json_schema_input_type=int)  # type: ignore[call-overload]  # pyright: ignore[reportCallIssue, reportArgumentType]  # pyrefly: ignore[no-matching-overload]     @classmethod     def invalid_input_type_not_allowed(cls, value: Any) -> Any: ... @@ -163,7 +163,7 @@ class WrapFieldValidator(BaseModel):         `pydantic_core.core_schema.NoInfoWrapValidatorFunction`.         """ -    @field_validator('foo', mode='wrap')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]+    @field_validator('foo', mode='wrap')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-specialization]     @classmethod     def invalid_handler(cls, value: Any, handler: int) -> Any: ... @@ -183,7 +183,7 @@ class WrapFieldValidator(BaseModel):   class PlainModelSerializer(BaseModel):-    @model_serializer  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]+    @model_serializer  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-specialization]     def too_many_arguments(self, info: SerializationInfo, unrelated: Any) -> Any: ...      @model_serializer@@ -200,7 +200,7 @@ class PlainModelSerializer(BaseModel):   class WrapModelSerializer(BaseModel):-    @model_serializer(mode='wrap')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]+    @model_serializer(mode='wrap')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-specialization]     def no_handler(self) -> Any: ...      @model_serializer(mode='wrap')@@ -228,7 +228,7 @@ class PlainFieldSerializer(BaseModel):     @field_serializer('a', mode='plain')     def valid_method_no_info_2(self, value: Any) -> Any: ... -    @field_serializer('a', mode='plain')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]+    @field_serializer('a', mode='plain')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-specialization]     def invalid_method_info_1(self, value: Any, info: int) -> Any: ...      @field_serializer('a', mode='plain')@@ -292,7 +292,7 @@ class WrapFieldSerializer(BaseModel):         `pydantic_core.core_schema.GeneralWrapNoInfoSerializerFunction`.         """ -    @field_serializer('a', mode='wrap')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]+    @field_serializer('a', mode='wrap')  # type: ignore[type-var]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-specialization]     @staticmethod     def staticmethod_no_handler(value: Any) -> Any: ... tests/typechecking/fields.pyindex de2e12c0b..5b2ad3592 100644@@ -16,14 +16,14 @@ def new_list() -> list[int]:  class Model(BaseModel):     # `default` and `default_factory` are mutually exclusive:-    f1: int = Field(default=1, default_factory=int)  # type: ignore[call-overload]  # pyright: ignore[reportCallIssue]+    f1: int = Field(default=1, default_factory=int)  # type: ignore[call-overload]  # pyright: ignore[reportCallIssue]  # pyrefly: ignore[no-matching-overload]      # `default` and `default_factory` matches the annotation:-    f2: int = Field(default='1')  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]-    f3: int = Field(default_factory=str)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]+    f2: int = Field(default='1')  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]+    f3: int = Field(default_factory=str)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment] -    f4: int = PrivateAttr(default='1')  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]-    f5: int = PrivateAttr(default_factory=str)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]+    f4: int = PrivateAttr(default='1')  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]+    f5: int = PrivateAttr(default_factory=str)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]      f6: list[str] = Field(default_factory=list)     f7: list[int] = Field(default_factory=new_list)@@ -32,8 +32,8 @@ class Model(BaseModel):     f10: int = Field(default_factory=lambda: 123)      # Note: mypy may require a different error code for `f12` (see https://github.com/python/mypy/issues/17986).-    f11: list[str] = Field(default_factory=new_list)  # type: ignore[arg-type]  # pyright: ignore[reportAssignmentType]-    f12: int = Field(default_factory=list)  # type: ignore[arg-type, assignment, unused-ignore]  # pyright: ignore[reportAssignmentType]+    f11: list[str] = Field(default_factory=new_list)  # type: ignore[arg-type]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]+    f12: int = Field(default_factory=list)  # type: ignore[arg-type, assignment, unused-ignore]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]      # Do not error on the ellipsis:     f13: int = Field(...)@@ -41,5 +41,5 @@ class Model(BaseModel):     # Do not error for invalid assignments when validate_default=True     f14: int = Field(default='1', validate_default=True)     f15: int = Field(default_factory=str, validate_default=True)-    f16: int = Field(default='1', validate_default=False)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]-    f17: int = Field(default_factory=str, validate_default=False)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]+    f16: int = Field(default='1', validate_default=False)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]+    f17: int = Field(default_factory=str, validate_default=False)  # type: ignore[assignment]  # pyright: ignore[reportAssignmentType]  # pyrefly: ignore[bad-assignment]tests/typechecking/json_schema_examples.pyindex ac6ec4d5c..3c1c7758a 100644@@ -1,4 +1,4 @@ from pydantic.json_schema import Examples  e_good = Examples([])-e_deprecated = Examples({})  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]+e_deprecated = Examples({})  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]  # pyrefly: ignore[deprecated]tests/typechecking/pipeline_api.pyindex ecf0e254e..4f295698c 100644@@ -21,7 +21,7 @@ a6 = Annotated[     ), ] -# Annotated types (e.g. NewPath, FilePath) should be accepted by validate_as.-# Fixes https://github.com/pydantic/pydantic/issues/12845+# TypeForm support: a7 = Annotated[Path, validate_as(NewPath)] a8 = Annotated[Path, validate_as(FilePath)]+a9 = Annotated[int | str, validate_as(int | str)]tests/typechecking/pyproject.tomlindex 0e505676b..03eb40412 100644@@ -1,12 +1,20 @@ [tool.pyright] extraPaths = ['../..'] pythonVersion = '3.10'-enableExperimentalFeatures = true enableTypeIgnoreComments = false reportUnnecessaryTypeIgnoreComment = true reportDeprecated = true reportUnusedExpression = false +[tool.pyrefly]+search-path = ['../..']+python-version = '3.10'+enabled-ignores = ['pyrefly']++[tool.pyrefly.errors]+deprecated = 'error'+unused-ignore = 'error'+ [tool.mypy] python_version = '3.10' disable_error_code = ['empty-body']tests/typechecking/root_model.pyindex 1149472b5..6502968ae 100644@@ -5,7 +5,7 @@ from pydantic import RootModel IntRootModel = RootModel[int]  int_root_model = IntRootModel(1)-bad_root_model = IntRootModel('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]+bad_root_model = IntRootModel('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type]  assert_type(int_root_model.root, int) tests/typechecking/type_adapter.pyindex 042b1c52e..110e3fb2b 100644@@ -1,7 +1,6 @@-# to be removed with PEP 747:-# mypy: disable_error_code=var-annotated-from typing import Annotated+from typing import Annotated, Union +from pydantic_core import MISSING from typing_extensions import assert_type  from pydantic import TypeAdapter@@ -11,17 +10,29 @@ assert_type(ta1, TypeAdapter[int])  assert_type(ta1.validate_python('1'), int) ta1.dump_python(1)-ta1.dump_python('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]+ta1.dump_python('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type] ta1.dump_json(1)-ta1.dump_json('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]+ta1.dump_json('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type] -# The following use cases require PEP 747: TypeExpr:+# The following use cases are for ensuring `TypeForm` works as expected:  ta2 = TypeAdapter(Annotated[int, ...])-assert_type(ta2, TypeAdapter[int])  # type: ignore[assert-type]  # pyright: ignore[reportAssertTypeFailure]+assert_type(ta2, TypeAdapter[int])+assert_type(ta2.validate_python(...), int)  ta3: TypeAdapter[int] = TypeAdapter(Annotated[int, ...]) assert_type(ta3, TypeAdapter[int])+assert_type(ta3.validate_python(...), int)  ta4 = TypeAdapter(int | str)-assert_type(ta4, TypeAdapter[int | str])  # type: ignore[assert-type]  # pyright: ignore[reportAssertTypeFailure]+assert_type(ta4, TypeAdapter[int | str])+assert_type(ta4.validate_python(...), int | str)++ta5 = TypeAdapter(Union[int, str])  # noqa: UP007+assert_type(ta5, TypeAdapter[int | str])+assert_type(ta5.validate_python(...), int | str)++# Mypy and Pyrefly don't support sentinels mixed with TypeForm (https://github.com/facebook/pyrefly/issues/4865):+ta6 = TypeAdapter(MISSING)  # type: ignore[arg-type, var-annotated]  # pyrefly: ignore[bad-argument-type]+assert_type(ta6, TypeAdapter[MISSING])  # type: ignore[assert-type, valid-type]  # pyrefly: ignore[assert-type]+assert_type(ta6.validate_python(...), MISSING)  # type: ignore[assert-type, valid-type]  # pyrefly: ignore[assert-type]tests/typechecking/type_form.pynew file mode 100644index 000000000..296e1fca0@@ -0,0 +1,19 @@+from typing import Annotated++from pydantic import ValidateAs, create_model, field_serializer++Model = create_model(+    'Model',+    f1=int | str,+    f2=(Annotated[int, ...], 1),+)+++def hook_1(v: int | str): ...+++ValidateAs(int | str, hook_1)+ValidateAs(Annotated[float, ...], hook_1)  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type]+++field_serializer('a', return_type=int | str)tests/typechecking/validate_call.pyindex f5f2666dc..9e81bb9c5 100644@@ -11,10 +11,10 @@ def foo(a: int, *, c: str = 'x') -> str: a = foo(1, c='a') assert_type(a, str) -foo('', c=1)  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]+foo('', c=1)  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]  # pyrefly: ignore[bad-argument-type]  # Not possible to type check currently (see https://github.com/pydantic/pydantic/issues/9883):-foo.raw_function(1, c='a')  # type: ignore[attr-defined]  # pyright: ignore[reportFunctionMemberAccess]+foo.raw_function(1, c='a')  # type: ignore[attr-defined]  # pyright: ignore[reportFunctionMemberAccess]  # pyrefly: ignore[missing-attribute]   # Should work even when not used as a bare decorator:tests/typechecking/with_config_decorator.pyindex 23e484789..e9a8f4923 100644@@ -15,7 +15,7 @@ class Model2(TypedDict):     pass  -@with_config(config=ConfigDict(str_to_lower=True))  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]+@with_config(config=ConfigDict(str_to_lower=True))  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated]  # pyrefly: ignore[deprecated] class Model3(TypedDict):     pass uv.lockindex 6cea91b18..c8b479cfd 100644@@ -2915,18 +2915,21 @@ wheels = [  [[package]] name = "pyrefly"-version = "0.27.0"+version = "1.2.0" source = { registry = "https://pypi.org/simple" }-sdist = { url = "https://files.pythonhosted.org/packages/21/d1/166ce5f5e1e6de8cfcc842d09dae187666a72d76fd2d6db4dff07bcac8c2/pyrefly-0.27.0.tar.gz", hash = "sha256:296671a94b40d91f136575b9fa9458801a747702581cbdb9e971da69f916b4a8", size = 1198185, upload-time = "2025-08-05T03:58:54.696Z" }-wheels = [-    { url = "https://files.pythonhosted.org/packages/1f/42/02b2092af809b5ddb790a44b009036c2fa5e69a52a84b743e74d369bfd70/pyrefly-0.27.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ad896c2387ff748ed236b9b4ddb0802d2b939947ce7ac1a6c6c67c217d20a958", size = 6305827, upload-time = "2025-08-05T03:58:39.092Z" },-    { url = "https://files.pythonhosted.org/packages/7a/e2/d4ca7ed11d88c6a3cbe9f875a680bb391a3d067089a2b68804dd76d8aceb/pyrefly-0.27.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:06651386b1ce7a40d2bcfcdfded5fb6d53279abffe9aefd4cb1b9720a6c7c77c", size = 5875353, upload-time = "2025-08-05T03:58:41.439Z" },-    { url = "https://files.pythonhosted.org/packages/c0/0f/cd0a910782e7c12dfa19d60052c92e6cc54845b1804621167fa3d619d241/pyrefly-0.27.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:12c79a8b19e32441289623d6c8c51aeddb2e81f692492f4bb8e5d405dae9b499", size = 6102678, upload-time = "2025-08-05T03:58:43.228Z" },-    { url = "https://files.pythonhosted.org/packages/6f/4c/068e56e89fae1458f82f9acaf59df53646e7b79725275115440ab015e6b2/pyrefly-0.27.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:199221de8f2832cbeb54f9693c0897c1201c6c602b7b3972964a201c355cb75d", size = 6859138, upload-time = "2025-08-05T03:58:44.809Z" },-    { url = "https://files.pythonhosted.org/packages/ef/1c/a3ec3679f8908994ba4813962e4439e1f538f2159f69483cf5e1e76d4949/pyrefly-0.27.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1086562e4d235114f81fb21b275a3b79377742af90fdde2cf9310f189a21bf1e", size = 6573841, upload-time = "2025-08-05T03:58:46.68Z" },-    { url = "https://files.pythonhosted.org/packages/9e/a8/be7338b925f5d8b1ea16cb9d4ab8fcac94c4f7d0a0d7b5f7e3b61e83f3f6/pyrefly-0.27.0-py3-none-win32.whl", hash = "sha256:9cb3244d0eb1bc61192160e963769554696f50ee940b79ce9812e48fbb55ca1c", size = 6096735, upload-time = "2025-08-05T03:58:49.06Z" },-    { url = "https://files.pythonhosted.org/packages/93/72/55cb0d24875ebd97d43d387777483c58f5942cab02ebecc83d8c52ca47f4/pyrefly-0.27.0-py3-none-win_amd64.whl", hash = "sha256:a93a14915fc3c1ffb7fe0441ac82821494c4fdf70a435b6ae9d1e95d27c2e5ef", size = 6491631, upload-time = "2025-08-05T03:58:50.93Z" },-    { url = "https://files.pythonhosted.org/packages/74/c7/288c464ce5e8ec9c78259437901aac6ebe48b113e0e9bce9a7d8d4226284/pyrefly-0.27.0-py3-none-win_arm64.whl", hash = "sha256:8a0e869beed7517066f3ee8390f1978dde29a8d92fb56ea414af43eb87b28b22", size = 6140536, upload-time = "2025-08-05T03:58:52.936Z" },+sdist = { url = "https://files.pythonhosted.org/packages/89/01/a86e9f24722b095c3f88e3616132b75a21b0df53804bdc6a45314dd4d93c/pyrefly-1.2.0.tar.gz", hash = "sha256:5485f960fc2481617068c918335c39ab1507ef90b6b5bd35bf57726e60e73185", size = 6243654, upload-time = "2026-08-01T02:56:27.592Z" }+wheels = [+    { url = "https://files.pythonhosted.org/packages/7d/9d/3c0ef1d4843987b22f996ed381ec9cf5a3b1273e29804db276252e4c95eb/pyrefly-1.2.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:7f46d983ac49ddd2b043694960a01dc6a19a5cfd8eec609d6bd9c42866f91b4e", size = 14026305, upload-time = "2026-08-01T02:56:02.611Z" },+    { url = "https://files.pythonhosted.org/packages/0a/06/03bbb78fbea54cdc65b626619f3597d5611aca4fdef11e72a4e8360e7e63/pyrefly-1.2.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:756f669b5555090f5c1a4fef30db1785fabe657764f7e4e6dc88994dfb8ca82d", size = 13463880, upload-time = "2026-08-01T02:56:04.93Z" },+    { url = "https://files.pythonhosted.org/packages/13/5a/7d8bc00a38e93bbc9c3e7bd14d305f7948717e667c9bcddeab9dd42fd255/pyrefly-1.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e3465812ce5ef4781fb592edbf2724547296f0a3124be115d73c7e8b2401862d", size = 13907329, upload-time = "2026-08-01T02:56:07.104Z" },+    { url = "https://files.pythonhosted.org/packages/be/94/9e08b4bf799d0b8f36b55a2783c7ba5f51730cf0632a85a67b5b5ed876cd/pyrefly-1.2.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5de7b2ad2bba5c8055181681a84b74143eac2234a48ba5d1b7ed7e7a722b02bd", size = 15039020, upload-time = "2026-08-01T02:56:09.208Z" },+    { url = "https://files.pythonhosted.org/packages/5b/bd/bca5fd0c80f4daf8ee6903a29df9f3de1feb05ff0946b8f35ec8c5096b13/pyrefly-1.2.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:25822ea9505f589ea8a725e4268b475132fb89e038fbf092e446510443ac142a", size = 14986199, upload-time = "2026-08-01T02:56:11.924Z" },+    { url = "https://files.pythonhosted.org/packages/97/f7/f07087f3d185ad2eced0c56cef89ca5474dfb4ff25f146cd50a861c97553/pyrefly-1.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90efe75e17491ef5d636e10469e9278d7d0256b3b4c5e1f4750069bf3ae0f5d1", size = 14393715, upload-time = "2026-08-01T02:56:14.143Z" },+    { url = "https://files.pythonhosted.org/packages/d3/70/0d142c320e284b9e3ce35e9b1e58b8ce2ee1f578f2a7234bc30e5022b94f/pyrefly-1.2.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:368aaf7eee4f511ddc0f8e564cf14e01ab2f10b0db9105c6d5b153bf498d07bf", size = 13933008, upload-time = "2026-08-01T02:56:16.525Z" },+    { url = "https://files.pythonhosted.org/packages/5d/e8/e84f11b6e1f63fd453ad3654213b9a0f6f4de8cef6b58038eef2d0d5955d/pyrefly-1.2.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:d52d5da7bc65fb7675fbaa80eda879d4f8787c494f04cac21603330d3abbdbbe", size = 14431827, upload-time = "2026-08-01T02:56:18.645Z" },+    { url = "https://files.pythonhosted.org/packages/0f/06/810d31380f66c75e1c0779a408d3b16117b1b368b57894f6aa66bef21686/pyrefly-1.2.0-py3-none-win32.whl", hash = "sha256:8c90751de8506d938e8f802659c74cf35bd7a0036510ee6c634a38eebb280bfa", size = 13229447, upload-time = "2026-08-01T02:56:20.921Z" },+    { url = "https://files.pythonhosted.org/packages/ed/98/4dafa3c7a1caed2dc8cc708dde09ba27963c7736508f55b626fff3024113/pyrefly-1.2.0-py3-none-win_amd64.whl", hash = "sha256:8a8964c224ccc4882730130955815de21ff443c1ac3f0b90685b19bf63848170", size = 14087387, upload-time = "2026-08-01T02:56:23.188Z" },+    { url = "https://files.pythonhosted.org/packages/1b/1c/df3cb0a2e5591660ded7a1836cd2f29dc48c91adb1c0a3a700a96f6d09e1/pyrefly-1.2.0-py3-none-win_arm64.whl", hash = "sha256:3a90bb8df39dfbac74b1f3b2e9d7c526b8f80568884c3944d955023a73ebf61e", size = 13430873, upload-time = "2026-08-01T02:56:25.425Z" }, ]  [[package]] 

What the agent reported

TypeAdapter(my_type).validate_python(x) with a PEP 695 alias now gives back the aliased type (list[dict[str, list[int]]]) under pyright and mypy 2.3.0. Pyrefly 0.27.0 still doesn't infer it. Both changes are left as uncommitted edits.

What was wrong: TypeAdapter.__init__ has one typed overload that takes a class (type[T]) and a catch-all that takes Any. A PEP 695 alias like type my_type = ... is an object, not a class. So it matched the catch-all, and the type checker couldn't work out what T was. The reporter's pyright showed TypeAliasType; the current pyright here shows Unknown. The root cause is the same.

What I changed:

  • pydantic/type_adapter.py: added a middle overload whose type parameter is TypeForm[T]. TypeForm (PEP 747) is how a type checker is told "this argument is a type expression". It is imported from typing_extensions, and the version the project already requires has it. The class overload still comes first, and the Any overload stays as the fallback for checkers that don't support PEP 747. I also updated the comments on the overloads.
  • tests/typechecking/type_adapter.py (the static type-checking suite that CI runs with pyright, mypy and Pyrefly):
  • Added a test for the reported case (ta5). It uses TypeAliasType(...) rather than a type statement, because this suite targets Python 3.10, where that syntax doesn't parse. It asserts the adapter type and the validate_python return type.
  • Added the issue's plain TypeAlias case (ta6) for comparison. That one already passed before the fix.
  • The fix also makes Annotated[...] and int | str infer correctly. The suite's config reports unneeded ignore comments as errors, so I removed the ones that were no longer needed. mypy still gets int | str wrong, so its ignore on that line stays.
  • Pyrefly 0.27.0 (the version the project locks) doesn't support TypeForm. I added # pyrefly: ignore[assert-type] to the two ta5 lines so its CI job doesn't fail. For Pyrefly users the reported problem remains.

Test evidence:

  • Before (unchanged code, same test file): pyright failed the new assertions (TypeAdapter[Unknown], Unknown), and mypy 2.3.0 failed them too (TypeAdapter[Any], Any).
  • After: pyright 1.1.411, mypy 2.3.0 and Pyrefly 0.27.0 report no errors on type_adapter.py.
  • Rest of the type-checking suite: results are identical before and after for all three checkers. pyright reports 39 errors and mypy 6 errors in decorators.py, the same before the change; both appear to come from the checkers not fully finding pydantic_core in this environment.
  • Runtime: ./bt-test tests/test_type_adapter.py tests/test_type_alias_type.py tests/test_typing.py gave 256 passed, 1 xfailed.
  • The change only affects type checking, so no pytest test can catch it. The regression test lives in the type-checking suite, which pytest doesn't collect; I ran the three checkers directly from the local cache.

Requirements:

  1. PEP 695 alias should infer the aliased type, not TypeAliasType: done, with the ta5 test failing before and passing after on pyright and mypy. It's intentionally ignored for Pyrefly, which can't do this yet.
  2. Plain TypeAlias should keep working: checked, still correct (ta6).
  3. No existing test weakened: only ignore comments that the checkers flagged as unneeded were removed, so those assertions are now actually enforced. No existing test was skipped or deleted.

The reviewer found no problems with the diff. They noted that the "Compatibility with mypy" tip in the TypeAdapter docstring may already be out of date; I left it alone to keep the change minimal.