Skip to content
Merged
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 docs/source/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ example (Python 3.12 syntax):
from typing import Mapping, Iterator

# This is a generic subclass of Mapping
class MyMapp[KT, VT](Mapping[KT, VT]):
class MyMap[KT, VT](Mapping[KT, VT]):
def __getitem__(self, k: KT) -> VT: ...
def __iter__(self) -> Iterator[KT]: ...
def __len__(self) -> int: ...
Expand Down Expand Up @@ -641,7 +641,7 @@ infer the most flexible variance for each class type variable. Here

.. code-block:: python

class Box[T]: # this type is implilicitly covariant
class Box[T]: # this type is implicitly covariant
def __init__(self, content: T) -> None:
self._content = content

Expand All @@ -663,12 +663,12 @@ the attribute as ``Final``, the class could still be made covariant:

from typing import Final

class Box[T]: # this type is implilicitly covariant
class Box[T]: # this type is implicitly covariant
def __init__(self, content: T) -> None:
self.content: Final = content

def get_content(self) -> T:
return self._content
return self.content

When using the legacy syntax, mypy assumes that all user-defined generics
are invariant by default. To declare a given generic class as covariant or
Expand Down