Skip to content

Decorated function leaks type variables #11816

Closed
@NeilGirdhar

Description

@NeilGirdhar
from typing import Callable, TypeVar

R = TypeVar('R')
Carry = TypeVar('Carry')
X = TypeVar('X')
Y = TypeVar('Y')

def api_boundary(f: Callable[..., R]) -> Callable[..., R]:
    return f

@api_boundary  # Removing this decorator fixes things.
def scan(f: Callable[[Carry, X], tuple[Carry, Y]],
         init: Carry,
         xs: X) -> tuple[Carry, Y]:
    ...

def f(c: int, x: bool) -> tuple[int, float]:
    return (c, 1.0)

reveal_type(scan(f, 1, True))   # Tuple[Carry`-1, Y`-3]

This is on Mypy 0.921.

Or maybe I've misunderstood type inference, and just have to wait for PEP 612 to finish being implemented?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions