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

Use Union for tuple fallback? #7616

Closed
Closed
@mthuurne

Description

@mthuurne
  • Please insert below the code you are checking with mypy,
fromtypingimportIterable,Iterator,Unionfromtyping_extensionsimportProtocolclassMixedIter(Protocol):def__iter__(self)->Iterator[Union[int,str]]: ...deff(xs:Iterable[Union[int,str]])->str:return''.join(str(x)forxinxs)defg(xs:MixedIter)->str:return''.join(str(x)forxinxs)mixedTuple= (56,'A')reveal_type(mixedTuple)reveal_type(mixedTuple.__iter__)print(f(mixedTuple))print(g(mixedTuple))
  • What is the actual behavior/output?
mixedtuple.py:14: note: Revealed type is 'Tuple[builtins.int, builtins.str]'mixedtuple.py:15: note: Revealed type is 'def () -> typing.Iterator[builtins.object*]'mixedtuple.py:17: error: Argument 1 to "g" has incompatible type "Tuple[int, str]"; expected "MixedIter"  [arg-type]
  • What is the behavior/output you expect?

I'd expect bothf(mixedTuple) andg(mixedTuple) to be accepted without errors.

  • What are the versions of mypy and Python you are using?

mypy 0.730 on Python 3.7.2.

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