Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

induct into return types of Callable for typevar solving #500

Open
Labels
genericsBugs or features relating to ty's generics implementationhelp wantedContributions especially welcome
Milestone
@DouweM

Description

@DouweM

Summary

I've confirmed the following works in pyright, mypy, and pyrefly - but not in ty:

fromdataclassesimportdataclassfromtyping_extensionsimport (Callable,Generic,TypeVar,assert_type,)T=TypeVar("T")@dataclassclassAgent(Generic[T]):output_type:Callable[...,T]deffunc()->int:return1# pyright, mypy, pyrefly - works# ty - `Agent[int]` and `Agent[Unknown]` are not equivalent types + Expected `((...) -> T) | ((...) -> Awaitable[T])`, found `def func() -> int`assert_type(Agent(func),Agent[int])# worksassert_type(Agent[int](func),Agent[int])

I'm hoping to also getCallable[..., T] | Callable[..., Awaitable[T]] to be inferred as the ultimate return type of the awaitable if an async function is passed rather than a regular one, but that's more tricky as it's ambiguous which side of the union should be matched. Note that pyright and pyrefly already handle this "correctly", but not mypy.

fromdataclassesimportdataclassfromtyping_extensionsimport (Awaitable,Callable,Generic,TypeVar,assert_type,)T=TypeVar("T")@dataclassclassAgent(Generic[T]):output_type:Callable[...,T]|Callable[...,Awaitable[T]]asyncdefcoro()->bool:returnTrue# mypy - error: Argument 1 to "Agent" has incompatible type "Callable[[], Coroutine[Any, Any, bool]]"; expected "Callable[..., Never] | Callable[..., Awaitable[Never]]"  [arg-type]coro_agent=Agent(coro)# pyright, pyrefly - works# mypy - error: Expression is of type "Agent[Any]", not "Agent[bool]"# ty - `Agent[bool]` and `Agent[Unknown]` are not equivalent typesassert_type(coro_agent,Agent[bool])# worksassert_type(Agent[bool](coro),Agent[bool])

It would be great to see both work in ty, but I'm also open to suggestions to do the latter in a less ambiguous way!

Version

ty 0.0.1-alpha.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    genericsBugs or features relating to ty's generics implementationhelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp