8000 Mention in the Any documentation how object is preferable · python/mypy@3061456 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3061456

Browse files
Mention in the Any documentation how object is preferable
This implements a suggestion in #9153 (comment), which I thought was a good idea.
1 parent 644a20c commit 3061456

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/source/dynamic_typing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.. _dynamic-typing:
22

3-
43
Dynamically typed code
54
======================
65

@@ -94,6 +93,8 @@ third party libraries that mypy does not know about. This is particularly the ca
9493
when using the :option:`--ignore-missing-imports <mypy --ignore-missing-imports>`
9594
flag. See :ref:`fix-missing-imports` for more information about this.
9695

96+
.. _any-vs-object:
97+
9798
Any vs. object
9899
--------------
99100

docs/source/kinds_of_types.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ A value with the ``Any`` type is dynamically typed. Mypy doesn't know
3939
anything about the possible runtime types of such value. Any
4040
operations are permitted on the value, and the operations are only checked
4141
at runtime. You can use ``Any`` as an "escape hatch" when you can't use
42-
a more precise type for some reason.
42+
a more precise type for some reason. This should not be confused with the
43+
:py:class:`object` type, which also represents any value, but in a type-safe
44+
way; it's almost always preferable to use ``object`` instead of ``Any``, if
45+
you can do so without great difficulty — see :ref:`any-vs-object` for more.
4346

4447
``Any`` is compatible with every other type, and vice versa. You can freely
4548
assign a value of type ``Any`` to a variable with a more precise type:

0 commit comments

Comments
 (0)
0