Generic method argument with Self type causes incomplete signature
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
Describe the bug
pyright seems to mis-infer the signature of a method when an parameter to a generic argument is a self-type that is checked against a protocol.
Code or Screenshots
from __future__ import annotations
from typing import Any, Protocol, Self
class _ViewP(Protocol):
# XXX: Any should really be some sort of `Pipeline`-bound TypeVar...
def dispatch(self, pipeline: Any) -> None:
...
class PipelineView:
def dispatch(self, pipeline: Pipeline[Self]) -> None:
...
class Pipeline[ViewT: _ViewP]:
def pipeline_views(self) -> ViewT:
...
This produces
repro.py:11:43 - error: Type "Self@PipelineView" cannot be assigned to type variable "ViewT@Pipeline"
Type "PipelineView*" is not assignable to upper bound "_ViewP" for type variable "ViewT@Pipeline"
"PipelineView*" is incompatible with protocol "_ViewP"
"dispatch" is an incompatible type
Type "() -> Unknown" is not assignable to type "(pipeline: Any) -> None"
Function accepts too many positional parameters; expected 0 but received 1 (reportInvalidTypeArguments)
1 error, 0 warnings, 0 informations
VS Code extension or command-line
Using pyright 1.1.402 through the CLI.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the repro.py example and run it through the CLI using pyright 1.1.402 to reproduce the Self and protocol diagnostic. Trace the type-checking path for the generic Pipeline[Self] argument, then verify that the example no longer reports the incompatible dispatch signature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100