Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test-data/unit/fixtures/typing-async.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
@overload
def get(self, k: T, default: Union[T_co, V]) -> Union[T_co, V]: pass

class ContextManager(Generic[T]):
def __enter__(self) -> T: pass
class ContextManager(Generic[T_co]):
def __enter__(self) -> T_co: pass
# Use Any because not all the precise types are in the fixtures.
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass

class AsyncContextManager(Generic[T]):
def __aenter__(self) -> Awaitable[T]: pass
class AsyncContextManager(Generic[T_co]):
def __aenter__(self) -> Awaitable[T_co]: pass
# Use Any because not all the precise types are in the fixtures.
def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Awaitable[Any]: pass

Expand Down
46 changes: 26 additions & 20 deletions test-data/unit/fixtures/typing-full.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Literal: _SpecialForm

T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
T_contra = TypeVar('T_contra', contravariant=True)
R_co = TypeVar('R_co', covariant=True)
S_contra = TypeVar('S_contra', contravariant=True)
U = TypeVar('U')
V = TypeVar('V')
S = TypeVar('S')
Expand Down Expand Up @@ -82,9 +83,9 @@ class Iterator(Iterable[T_co], Protocol):
@abstractmethod
def __next__(self) -> T_co: pass

class Generator(Iterator[T], Generic[T, U, V]):
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
@abstractmethod
def send(self, value: U) -> T: pass
def send(self, value: S_contra) -> T_co: pass

@abstractmethod
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
Expand All @@ -93,35 +94,40 @@ class Generator(Iterator[T], Generic[T, U, V]):
def close(self) -> None: pass

@abstractmethod
def __iter__(self) -> 'Generator[T, U, V]': pass
def __iter__(self) -> 'Generator[T_co, S_contra, R_co]': pass

class AsyncGenerator(AsyncIterator[T], Generic[T, U]):
class AsyncGenerator(AsyncIterator[T_co], Generic[T_co, S_contra]):
@abstractmethod
def __anext__(self) -> Awaitable[T]: pass
def __anext__(self) -> Awaitable[T_co]: pass

@abstractmethod
def asend(self, value: U) -> Awaitable[T]: pass
def asend(self, value: S_contra) -> Awaitable[T_co]: pass

@abstractmethod
def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T]: pass
def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T_co]: pass

@abstractmethod
def aclose(self) -> Awaitable[T]: pass
def aclose(self) -> Awaitable[T_co]: pass

@abstractmethod
def __aiter__(self) -> 'AsyncGenerator[T, U]': pass
def __aiter__(self) -> 'AsyncGenerator[T_co, S_contra]': pass

@runtime_checkable
class Awaitable(Protocol[T]):
class Awaitable(Protocol[T_co]):
@abstractmethod
def __await__(self) -> Generator[Any, Any, T]: pass
def __await__(self) -> Generator[Any, Any, T_co]: pass

class AwaitableGenerator(Generator[T, U, V], Awaitable[V], Generic[T, U, V, S], metaclass=ABCMeta):
class AwaitableGenerator(
Awaitable[R_co],
Generator[T_co, S_contra, R_co],
Generic[T_co, S_contra, R_co, S],
metaclass=ABCMeta
):
pass

class Coroutine(Awaitable[V], Generic[T, U, V]):
class Coroutine(Awaitable[R_co], Generic[T_co, S_contra, R_co]):
@abstractmethod
def send(self, value: U) -> T: pass
def send(self, value: S_contra) -> T_co: pass

@abstractmethod
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
Expand All @@ -130,15 +136,15 @@ class Coroutine(Awaitable[V], Generic[T, U, V]):
def close(self) -> None: pass

@runtime_checkable
class AsyncIterable(Protocol[T]):
class AsyncIterable(Protocol[T_co]):
@abstractmethod
def __aiter__(self) -> 'AsyncIterator[T]': pass
def __aiter__(self) -> 'AsyncIterator[T_co]': pass

@runtime_checkable
class AsyncIterator(AsyncIterable[T], Protocol):
def __aiter__(self) -> 'AsyncIterator[T]': return self
class AsyncIterator(AsyncIterable[T_co], Protocol):
def __aiter__(self) -> 'AsyncIterator[T_co]': return self
@abstractmethod
def __anext__(self) -> Awaitable[T]: pass
def __anext__(self) -> Awaitable[T_co]: pass

class Sequence(Iterable[T_co], Container[T_co]):
@abstractmethod
Expand Down
14 changes: 6 additions & 8 deletions test-data/unit/fixtures/typing-medium.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ Self = 0

T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
T_contra = TypeVar('T_contra', contravariant=True)
U = TypeVar('U')
V = TypeVar('V')
S = TypeVar('S')
R_co = TypeVar('R_co', covariant=True)
S_contra = TypeVar('S_contra', contravariant=True)

# Note: definitions below are different from typeshed, variances are declared
# to silence the protocol variance checks. Maybe it is better to use type: ignore?
Expand All @@ -49,8 +47,8 @@ class Iterable(Protocol[T_co]):
class Iterator(Iterable[T_co], Protocol):
def __next__(self) -> T_co: pass

class Generator(Iterator[T], Generic[T, U, V]):
def __iter__(self) -> 'Generator[T, U, V]': pass
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
def __iter__(self) -> 'Generator[T_co, S_contra, R_co]': pass

class Sequence(Iterable[T_co]):
def __getitem__(self, n: Any) -> T_co: pass
Expand All @@ -65,8 +63,8 @@ class SupportsInt(Protocol):
class SupportsFloat(Protocol):
def __float__(self) -> float: pass

class ContextManager(Generic[T]):
def __enter__(self) -> T: pass
class ContextManager(Generic[T_co]):
def __enter__(self) -> T_co: pass
# Use Any because not all the precise types are in the fixtures.
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass

Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/fixtures/typing-namedtuple.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Iterable(Generic[T_co]): pass
class Iterator(Iterable[T_co]): pass
class Sequence(Iterable[T_co]): pass
class Mapping(Iterable[KT], Generic[KT, T_co]):
def keys(self) -> Iterable[T]: pass # Approximate return type
def __getitem__(self, key: T) -> T_co: pass
def keys(self) -> Iterable[KT]: pass # Approximate return type
def __getitem__(self, key: KT) -> T_co: pass

class NamedTuple(tuple[Any, ...]):
_fields: ClassVar[tuple[str, ...]]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/fixtures/typing-override.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Iterable(Generic[T_co]): pass
class Iterator(Iterable[T_co]): pass
class Sequence(Iterable[T_co]): pass
class Mapping(Iterable[KT], Generic[KT, T_co]):
def keys(self) -> Iterable[T]: pass # Approximate return type
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this was weird.

def __getitem__(self, key: T) -> T_co: pass
def keys(self) -> Iterable[KT]: pass # Approximate return type
def __getitem__(self, key: KT) -> T_co: pass

def override(__arg: T) -> T: ...

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fixtures/typing-typeddict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
def __len__(self) -> int: ...
def __contains__(self, arg: object) -> int: pass

class MutableMapping(Mapping[T, T_co], Generic[T, T_co], metaclass=ABCMeta):
class MutableMapping(Mapping[T, V], Generic[T, V], metaclass=ABCMeta):
# Other methods are not used in tests.
def clear(self) -> None: ...

Expand Down
14 changes: 7 additions & 7 deletions test-data/unit/lib-stub/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ TYPE_CHECKING = 0

T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
U = TypeVar('U')
V = TypeVar('V')
S_contra = TypeVar('S_contra', contravariant=True)
R_co = TypeVar('R_co', covariant=True)

class Iterable(Protocol[T_co]):
def __iter__(self) -> Iterator[T_co]: pass

class Iterator(Iterable[T_co], Protocol):
def __next__(self) -> T_co: pass

class Generator(Iterator[T], Generic[T, U, V]):
def __iter__(self) -> Generator[T, U, V]: pass
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
def __iter__(self) -> Generator[T_co, S_contra, R_co]: pass

class Sequence(Iterable[T_co]):
def __getitem__(self, n: Any) -> T_co: pass
Expand All @@ -56,10 +56,10 @@ class Mapping(Iterable[T], Generic[T, T_co]):
def keys(self) -> Iterable[T]: pass # Approximate return type
def __getitem__(self, key: T) -> T_co: pass

class Awaitable(Protocol[T]):
def __await__(self) -> Generator[Any, Any, T]: pass
class Awaitable(Protocol[T_co]):
def __await__(self) -> Generator[Any, Any, T_co]: pass

class Coroutine(Awaitable[V], Generic[T, U, V]): pass
class Coroutine(Awaitable[R_co], Generic[T_co, S_contra, R_co]): pass

def final(meth: T) -> T: pass

Expand Down
Loading