-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive of protocol conforming when Self
is used in a base protocol
#4966
Comments
Thanks for the bug report and great repro steps. This will be addressed in the next release. |
…ol matching when there are multiple levels of protocol inheritance and a method that uses `Self` in its signature. This addresses #4966.
…ol matching when there are multiple levels of protocol inheritance and a method that uses `Self` in its signature. This addresses #4966.
This is addressed in pyright 1.1.306, which I just published. It will also be included in a future release of pylance. |
Still works incorrectly over some cases in Pylance v2023.5.11 (Pyright 1.1.306). from __future__ import annotations
from typing import Protocol, TypeVar
from typing_extensions import Self
_V_t = TypeVar("_V_t")
_V_co = TypeVar("_V_co")
class SetLike(Protocol[_V_co]):
def __and__(self, right: Self, /) -> SetLike[_V_co]: ...
# Other methods are omitted.
class MutableSetLike1(SetLike[_V_t], Protocol[_V_t]):
def add(self, o: _V_t, /) -> None: ...
# Other methods are omitted.
class MutableSetLike2(Protocol[_V_t]):
def __and__(self, right: Self, /) -> SetLike[_V_t]: ...
def add(self, o: _V_t, /) -> None: ...
# Other methods are omitted.
SOME_SET: set[str] = {"A", "B", "C"}
a: SetLike[str] = SOME_SET
b: MutableSetLike1[str] = SOME_SET
c: MutableSetLike2[str] = SOME_SET In the sample above, Mypy playground: https://mypy-play.net/?mypy=latest&python=3.10&gist=d68e3371c260e7b333d059194b1b9774 |
@Azureblade3808, this issue is closed. If you want to report a new bug, please open a new issue. |
Describe the bug
When a protocol is inheriting another protocol, and the base protocol uses
Self
in some way, conforming to the derived protocol sometimes fails unexpectedly.To Reproduce
See sample code.
Expected behavior
Both assignments in the last should type-check.
Screenshots or Code
VS Code extension or command-line
Pylance v2023.4.21 Pre-Release
Additional context
If
C
explicitly inheritsP1[_V_co]
, no error is reported.Mypy playground: https://mypy-play.net/?mypy=latest&python=3.10&gist=a26280d31899e845ae73aecf9068bafa
EDIT
A derived class is not needed to repro.
The text was updated successfully, but these errors were encountered: