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

Trying to iterate over typing.Union results in hang #92261

Closed
Labels
@mrahtz

Description

@mrahtz

If you accidentally iterate over aUnion, you get a hang:

fromtypingimportUnionlist(Union)# ...hang

It looks like it's an infinite loop:

fromtypingimportUnionforiinUnion:print(i)# 0, 1, 2, ...

As far as I can tell, this happens becausetyping.Union is implemented usingtyping._SpecialForm, and_SpecialForm is implemented using__getitem__ to support parameterisation likeUnion[int]. Unfortunately, because_SpecialForm doesn't implement__iter__,__getitem__ is also used for iteration - meaning that when trying to iterate, we effectively doUnion[0],Union[1], etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp