Skip to content

Potential regression in type narrowing logic #10339

@brearleyt

Description

@brearleyt

Describe the bug
I believe there has been a regression in the type narrowing logic for the below example. The error is raised when using 1.1.399, but was not raised when using 1.1.398.

Code or Screenshots

import subprocess
import typing as t


def foo(handle: subprocess.Popen[str] | t.Callable[[str], None]) -> str:
    assert isinstance(handle, subprocess.Popen)
    t.reveal_type(handle)
    stdout, _ = handle.communicate()
    return stdout

Pyright output:

example.py:7:19 - information: Type of "handle" is "Popen[str] | Popen[Unknown]"
example.py:8:5 - error: Type of "stdout" is partially unknown
    Type of "stdout" is "str | Unknown" (reportUnknownVariableType)
example.py:8:13 - error: Type of "_" is partially unknown
    Type of "_" is "str | Unknown" (reportUnknownVariableType)
example.py:8:17 - error: Type of "communicate" is partially unknown
    Type of "communicate" is "((input: str | None = None, timeout: float | None = None) -> tuple[str, str]) | ((input: Unknown | None = None, timeout: float | None = None) -> tuple[Unknown, Unknown])" (reportUnknownMemberType)
example.py:9:12 - error: Return type, "str | Unknown", is partially unknown (reportUnknownVariableType)
4 errors, 0 warnings, 1 information 

VS Code extension or command-line
Python: 3.13
Pyright: 1.1.399 via the commandline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions