@@ -210,15 +210,22 @@ defined class is generic if you subclass one or more other generic classes and
210210specify type variables for their parameters. See :ref: `generic-base-classes `
211211for details.
212212
213- You can use multiple inheritance with generic classes ::
213+ You can use multiple inheritance with `` Generic `` ::
214214
215- from collections.abc import Container, Iterable, Sized
215+ from typing import TypeVar, Generic
216+ from collections.abc import Sized, Iterable, Container
217+
218+ T = TypeVar('T')
216219
217- class LinkedList[T](Sized ):
220+ class LinkedList(Sized, Generic [T]):
218221 ...
219222
220- class MyMapping[K, V](Iterable[tuple[K, V]],
221- Container[tuple[K, V]]):
223+ K = TypeVar('K')
224+ V = TypeVar('V')
225+
226+ class MyMapping(Iterable[tuple[K, V]],
227+ Container[tuple[K, V]],
228+ Generic[K, V]):
222229 ...
223230
224231Subclassing a generic class without specifying type parameters assumes
@@ -240,7 +247,7 @@ Scoping rules for type variables
240247
241248When using the generic class syntax introduced in Python 3.12, the location of
242249its declaration defines its scope. When using the older syntax, the scoping
243- rules are more subtle and complex.
250+ rules are more subtle and complex:
244251
245252* A type variable used in a generic function could be inferred to represent
246253 different types in the same code block. Example::
@@ -662,7 +669,7 @@ inline by prefixing its name with ``**`` inside a generic parameter list
662669 class CallbackWrapper[T, **P]:
663670 callback: Callable[P, T]
664671
665- Prior to 3.12, the ``ParamSpec `` constructor can be used::
672+ Prior to 3.12, the ``ParamSpec `` constructor can be used.
666673
667674.. code-block ::
668675
@@ -699,8 +706,8 @@ parameter specification variable (``Callable[Concatenate[int, P], int]``\ ).
699706 "]"
700707
701708 where ``parameter_specification_variable `` is introduced either inline (using
702- ``** ``) or via ``typing.ParamSpec `` as shown above, and `` concatenate `` is
703- ``typing.Concatenate ``.
709+ ``** `` in a type parameter list ) or via ``typing.ParamSpec `` as shown above,
710+ and `` concatenate `` is ``typing.Concatenate ``.
704711
705712As before, ``parameters_expression ``\ s by themselves are not acceptable in
706713places where a type is expected
@@ -1086,7 +1093,7 @@ type such as ``int``, a type variable *tuple* is a stand-in for a *tuple* type s
10861093``tuple[int, str] ``.
10871094
10881095In Python 3.12 and newer, type variable tuples can be introduced inline by prefixing
1089- their name with ``* `` inside a generic parameter list.
1096+ their name with ``* `` inside a type parameter list.
10901097
10911098::
10921099
0 commit comments