Skip to content
Open
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
14 changes: 9 additions & 5 deletions docs/source/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ multiple variables (or maybe declare the variable with an ``Any`` type).
...
n = 'x' # error: Incompatible types in assignment (expression has type "str", variable has type "int")

.. note::

Using the :option:`--allow-redefinition <mypy --allow-redefinition>`
.. note:: Using the :option:`--allow-redefinition <mypy --allow-redefinition>`
flag can suppress this error in several cases.

Note that you can redefine a variable with a more *precise* or a more
Expand All @@ -301,9 +299,15 @@ See :ref:`type-narrowing` for more information.

Invariance vs covariance
------------------------
Most mutable generic collections are invariant. With the older
``TypeVar`` syntax (for example ``T = TypeVar("T")``), user-defined
generic classes are invariant by default.

With the newer PEP 695 syntax (for example ``class MyCls[T]:``),
type parameters may be inferred as covariant if they are not used
in positions that require invariance.


Most mutable generic collections are invariant, and mypy considers all
user-defined generic classes invariant by default
(see :ref:`variance-of-generics` for motivation). This could lead to some
unexpected errors when combined with type inference. For example:

Expand Down