Clarify some rules around using or omitting Generic[...] as base class, by example.
diff --git a/pep-0484.txt b/pep-0484.txt
index 5d6f87c..62e950f 100644
--- a/pep-0484.txt
+++ b/pep-0484.txt
@@ -403,15 +403,39 @@
class Pair(Generic[T, T]): # INVALID
...
+The ``Generic[T]`` base class is redundant in simple cases where you
+subclass some other generic class and specify type variables for its
+parameters::
+
+ from typing import TypeVar, Iterator
+
+ T = TypeVar('T')
+
+ class MyIter(Iterator[T]):
+ ...
+
+That class definition is equivalent to::
+
+ class MyIter(Iterator[T], Generic[T]):
+ ...
+
You can use multiple inheritance with ``Generic``::
- from typing import TypeVar, Generic, Sized
+ from typing import TypeVar, Generic, Sized, Iterable, Container
T = TypeVar('T')
class LinkedList(Sized, Generic[T]):
...
+ K = TypeVar('K')
+ V = TypeVar('V')
+
+ class MyMapping(Iterable[Tuple[K, V]],
+ Container[Iterable[K, V]],
+ Generic[K, V]):
+ ...
+
Subclassing a generic class without specifying type parameters assumes
``Any`` for each position. In the following example, ``MyIterable``
is not generic but implicitly inherits from ``Iterable[Any]``::