diff --git a/docs/source/dynamic_typing.rst b/docs/source/dynamic_typing.rst index 304e25c085a8..da40142d377d 100644 --- a/docs/source/dynamic_typing.rst +++ b/docs/source/dynamic_typing.rst @@ -1,6 +1,5 @@ .. _dynamic-typing: - Dynamically typed code ====================== @@ -94,6 +93,8 @@ third party libraries that mypy does not know about. This is particularly the ca when using the :option:`--ignore-missing-imports ` flag. See :ref:`fix-missing-imports` for more information about this. +.. _any-vs-object: + Any vs. object -------------- diff --git a/docs/source/kinds_of_types.rst b/docs/source/kinds_of_types.rst index 54693cddf953..b939d4471959 100644 --- a/docs/source/kinds_of_types.rst +++ b/docs/source/kinds_of_types.rst @@ -39,7 +39,10 @@ A value with the ``Any`` type is dynamically typed. Mypy doesn't know anything about the possible runtime types of such value. Any operations are permitted on the value, and the operations are only checked at runtime. You can use ``Any`` as an "escape hatch" when you can't use -a more precise type for some reason. +a more precise type for some reason. This should not be confused with the +:py:class:`object` type, which also represents any value, but in a type-safe +way; it's almost always preferable to use ``object`` instead of ``Any``, if +you can do so without great difficulty — see :ref:`any-vs-object` for more. ``Any`` is compatible with every other type, and vice versa. You can freely assign a value of type ``Any`` to a variable with a more precise type: