-
-
Notifications
You must be signed in to change notification settings - Fork 122
Closed
Labels
Description
Among the valid locations for Self in PEP 673 we find:
TupleSelf = Tuple[Self, Self]
class Alias:
def return_tuple(self) -> TupleSelf:
return (self, self)
But typing._type_check
regards typing._SpecialForm
instances invalid type arguments
https://github.com/python/cpython/blob/e0f8a3e9b96bbc2597f61be96993ef0c768a19fe/Lib/typing.py#L179
So this use will result in a
TypeError: Plain typing_extensions.Self is not valid as type argument
This also affects uses in linked lists and recursive dataclasses lke
@dataclasses.dataclass
class MenuItem:
url: str
title: str
description: str = ""
items: typing.List[typing_extensions.Self] = dataclasses.field(default_factory=list)