Skip to content

Pyrefly infers Iterator[Any] instead of Iterator[int] for iter([0]) #3265

Closed

Description

@rchen152

Describe the Bug

from typing import Iterator, assert_type
assert_type(iter([0]), Iterator[int])  # error: assert_type(Iterator[Any], Iterator[int]) failed

This only happens with a list literal - x: list[int] = [0]; iter(x) works correctly.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0BJBjEqoGvADR1UcOCIYB9JsRgAddDLl8lzGAAoIwynoDaABgC6ASilCRY3idYNrICSDKUYYKKULiaKAoAYjoABVIvH1I6NCw8fDoAY1x0SDYAV1EGCFTCdVCAZRgYOgALBgZiOEQAelrPb19CXjZamHRazFwkuFqUtIhM7NzOujBeaQA3VGhUbFhk1PSssVG6XGIc1Lh89DIGMtSAWimROHWAXjpVEABmQgBGACZb9RAAX3dUJJyzgDFoDAKHEcAQSOQPkA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. added theissue type on Apr 28, 2026
  2. removed their assignment
    on May 6, 2026
  3. rchen152 commented on May 6, 2026

    @rchen152
    ContributorAuthor

    Unassigning myself since I'm not actively working on this

  4. asukaminato0721 commented on Aug 29, 2026

    @asukaminato0721
    Collaborator
  5. rchen152 commented on Sep 9, 2026

    @rchen152
    ContributorAuthor

    It doesn't look like this is fixed properly; list is fine now, but I can trivially produce another failure by using a set:

    from typing import Iterator, assert_type
    assert_type(iter({0}), Iterator[int])  # still fails
    

    or a dict:

    from typing import Iterator, assert_type
    assert_type(iter({0: 0}), Iterator[int])  # still fails
    

    I suppose we could extend 899b0af to other container types, but the fact that we're special-casing specific builtins - and even that commit introduces a bug= test and notes the fix is incomplete - makes me wonder if we're just working around the problem rather than solving the root case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions