Closed JasonGrace2282 closed 1 day ago
Upon further testing, it appears to be because of Self
in the Protocol definition, since this works
from typing import TYPE_CHECKING, Any, TypeVar, Protocol, overload
if TYPE_CHECKING:
from typing_extensions import Self
V = TypeVar("V")
S = TypeVar("S")
C_co = TypeVar("C_co", covariant=True)
class SimpleAttributeFunc(Protocol[C_co, V]):
# getter
@overload
def __call__(self, new: None = None, **kwargs: Any) -> V: ...
# setter
@overload
def __call__(self, new: V, **kwargs: Any) -> C_co: ...
class TestMe:
def testsomething(self) -> SimpleAttributeFunc[Self, str]:
def foo(new: str | None = None, **kwargs):
if new is None:
return str(["hi"])
else:
print(f"Setting to {new} with {kwargs}")
return self
return foo
Similar to #16629 — possibly a duplicate, but the traceback is different
Similar to #16629 — possibly a duplicate, but the traceback is different
Seems similar, I didn't see that before! Should I close this issue then?
Yes, this is a duplicate of #16629
Crash Report I ran
mypy
on this code and it crashed with an internal errorTraceback
Click here for full traceback
``` Traceback (most recent call last): File "/sbin/mypy", line 8, inTo Reproduce
Your Environment
mypy.ini
(and other config files): No configMy Goal
While irrelevant to the issue, here was my goal (but working) https://gist.github.com/mypy-play/62fad45174312b2b1ec0c17e555d9ece