Backtestspydanticrun-20261003-150343#8998
Missing type for PEP695 TypeAliasType vs TypeAlias when using TypeAdapter
The harness couldn't finish this ticket.
harness-error at baseline. No judgment was produced for this ticket. It counts as an error in the run total.
Solve
—
Wall-clock time in the container
Full test suite
Not run
The harness did not reach the test stage
Contamination audit
Unknown
See the audit notes for this run
Patch size
0vs 0 merged
Changed lines, ours vs merged
The issue
View on GitHubInitial 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: unknownThe two patches
No patch was produced.No patch was produced.