Skip to content

Inferred return type of Never when a method body contains a for loop #1491

@rchen152

Description

@rchen152

Describe the Bug

from typing import reveal_type

class A:
    def f(self, x):
        for y in x:
            pass

reveal_type(A().f(0))  # this is revealed as Never!

See sandbox link - the inlay hint for the inferred return type is -> Never as well.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCiAOuvR-ZjGPWABRwYUMABp6%2BAJSt2nOWFwAneqXoR2%2BGXO2ditBKJABXAC7Q4JcohABiegFUzUCCdVgj6Smdzo4bNty8CooAtqgmAProRiHYMIr8mmroJpL0ALQAfPRwJopanIowJkaK7GAsIAByMXH59MD4AL6VbCCGZEVgUKSEJrghUBR2AAqkXT05GDgE9JQ%2BkADmpeEQPoRsdgDKMDD0ABYmJsRwiAD0Z508PYRKi2cw6GeYuJRwZ-PoSyveT3xK9FQADdUNBUNhYHMFhBlopVj56LhiL8LGwyCZ9j50kD4nA1uwALz0SoAZkIAEYAEytdAgJqGVBeCA4gBi0BgFDQWDwRDIdKAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions