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

Mypy is still too eager about outer context #5874

Open
@ilevkivskyi

Description

@ilevkivskyi

Consider this example:

T=TypeVar('T')S=TypeVar('S')defadd(x:List[T],y:List[S])->List[Union[T,S]]: ...a:List[int]b:List[str]e:List[Union[int,str]]=add(a,b)

It fails on the last line with the following (I skip invariance notes):

error: Argument 1 to "add" has incompatible type "List[int]"; expected "List[Union[int, str]]"error: Argument 2 to "add" has incompatible type "List[str]"; expected "List[Union[int, str]]"

If I remove the annotation fore, everything works fine.

When previously working on the external context issues, I found that I don't like how constrains for unions against unions are inferred (not that they are wrong, just counterintuitive). For example,Union[T, S] <: Union[str, int] infersT < : Union[str, int] and S <: Union[str, int], which is technically fine, but leads to errors like above.

This blocks#5873

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp