@@ -3,6 +3,7 @@ from collections.abc import Iterator
33from typing import Any , Protocol , TypeVar , overload
44
55_T = TypeVar ("_T" )
6+ _T_co = TypeVar ("_T_co" , covariant = True )
67
78class PackageMetadata (Protocol ):
89 def __len__ (self ) -> int : ...
@@ -22,19 +23,27 @@ class PackageMetadata(Protocol):
2223 def get (self , name : str , failobj : _T ) -> _T | str : ...
2324
2425if sys .version_info >= (3 , 12 ):
25- class SimplePath (Protocol [_T ]):
26- def joinpath (self ) -> _T : ...
26+ class SimplePath (Protocol [_T_co ]):
27+ # At runtime this is defined as taking `str | _T`, but that causes trouble.
28+ # See #11436.
29+ def joinpath (self , other : str , / ) -> _T_co : ...
2730 @property
28- def parent (self ) -> _T : ...
31+ def parent (self ) -> _T_co : ...
2932 def read_text (self ) -> str : ...
30- def __truediv__ (self , other : _T | str ) -> _T : ...
33+ # As with joinpath(), this is annotated as taking `str | _T` at runtime.
34+ def __truediv__ (self , other : str , / ) -> _T_co : ...
3135
3236else :
3337 class SimplePath (Protocol ):
34- def joinpath (self ) -> SimplePath : ...
35- def parent (self ) -> SimplePath : ...
38+ # Actually takes only self at runtime, but that's clearly wrong
39+ def joinpath (self , other : Any , / ) -> SimplePath : ...
40+ # Not defined as a property at runtime, but it should be
41+ @property
42+ def parent (self ) -> Any : ...
3643 def read_text (self ) -> str : ...
3744 # There was a bug in `SimplePath` definition in cpython, see #8451
3845 # Strictly speaking `__div__` was defined in 3.10, not __truediv__,
3946 # but it should have always been `__truediv__`.
40- def __truediv__ (self ) -> SimplePath : ...
47+ # Also, the runtime defines this method as taking no arguments,
48+ # which is obviously wrong.
49+ def __truediv__ (self , other : Any , / ) -> SimplePath : ...
0 commit comments