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

Sequence of types #19142

Open
Open
Labels
bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions
@DouweM

Description

@DouweM

The following works in pyright, but not in pyrefly, ty, or (which is why I'm here!) mypy:

from __future__importannotationsfromdataclassesimportdataclassfromtyping_extensionsimport (Generic,Sequence,TypeVar,assert_type,)T=TypeVar("T")@dataclassclassAgent(Generic[T]):output_type:Sequence[type[T]]classFoo:passclassBar:pass# pyright - works# mypy - error: Expression is of type "Agent[object]", not "Agent[Foo | Bar]"  [assert-type]# pyrefly - assert_type(Agent[Foo], Agent[Bar | Foo]) failed + Argument `list[type[Bar] | type[Foo]]` is not assignable to parameter `output_type` with type `Sequence[type[Foo]]` in function `Agent.__init__`# ty - `Agent[Foo | Bar]` and `Agent[Unknown]` are not equivalent typesassert_type(Agent([Foo,Bar]),Agent[Foo|Bar])# pyright - works# mypy - error: Expression is of type "Agent[Never]", not "Agent[int | str]"  [assert-type]# pyrefly - assert_type(Agent[int], Agent[str | int]) failed + Argument `list[type[str] | type[int]]` is not assignable to parameter `output_type` with type `Sequence[type[int]]` in function `Agent.__init__`# ty - `Agent[int | str]` and `Agent[Unknown]` are not equivalent typesassert_type(Agent([int,str]),Agent[int|str])# worksassert_type(Agent[Foo|Bar]([Foo,Bar]),Agent[Foo|Bar])# worksassert_type(Agent[int|str]([int,str]),Agent[int|str])

It would be great to see this work in mypy, but if there's a good reason the other 2 out of 3 typecheckers also don't support this I'd love to understand why!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp