Skip to content

Can't infer type of fileinput.input() iterator #3494

@Molkree

Description

@Molkree

Describe the bug
Pyright can't infer the type of fileinput.input() iterator, it infers to Unknown. Present since 1.2.247.

To Reproduce
Check provided code below.

Expected behavior
AnyStr@input type inferred? It was the behaviour before 1.1.247.

Screenshots or Code

import fileinput

for line in fileinput.input():  # line is Unknown
    pass

Tooltip on function in VS Code shows the correct type. 😅
image

VS Code extension or command-line
I usually run it as part of Pylance but just for the sake of this issue have installed Pyright as a separate extension and confirmed the same (still present in 1.1.248 which is newer than the latest Pylance release).

Additional context
It doesn't seem like something caused by updated typeshed stubs because the last time this module was touched in typeshed was a month ago, many Pyright versions ago.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions