Skip to content

Erroneous invalid-argument-type for generic contextmanager with ParamSpec #2382

@bcmills

Description

@bcmills

Summary

For this program, ty produces this error:

Argument is incorrect: Expected `(**_P@_inner) -> None`, found `(**_P@outer) -> None` (invalid-argument-type) [Ln 16, Col 13]

Since _P@_inner and _P@outer are the same _P in the same parameter position, they are obviously compatible. It isn't clear to me why ty is treating them as somehow incompatible.


https://play.ty.dev/f8330b63-ba0f-455e-b11b-f67c3016be21:

import contextlib
from collections.abc import Callable, Iterator
from typing import ParamSpec

_P = ParamSpec("_P")

class Foo:
    @contextlib.contextmanager
    def outer(
        self,
        probe: Callable[_P, None],
        *args: _P.args,
        **kwargs: _P.kwargs,
    ) -> Iterator[None]:
        with self._inner(
            probe=probe,
        ):
            yield
    
    @contextlib.contextmanager
    def _inner(
        self,
        probe: Callable[_P, None],
        *args: _P.args,
        **kwargs: _P.kwargs,
    ) -> Iterator[None]:
        probe(*args, **kwargs)
        yield

Version

ty 0.0.9

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions