@@ -772,18 +772,26 @@ all type checkers::
772
772
Using ``Any `` and ``object ``
773
773
----------------------------
774
774
775
- When adding type hints, avoid using the `` Any ` ` type when possible. Reserve
776
- the use of `` Any ` ` for when:
775
+ When adding type hints, avoid using the :ref: ` Any ` type when possible. Reserve
776
+ the use of :ref: ` Any ` for when:
777
777
778
778
* the correct type cannot be expressed in the current type system; and
779
779
* to avoid union returns (see above).
780
780
781
- Note that `` Any ` ` is not the correct type to use if you want to indicate
781
+ Note that :ref: ` Any ` is not the correct type to use if you want to indicate
782
782
that some function can accept literally anything: in those cases use
783
- ``object `` instead.
784
-
785
- When using ``Any ``, document the reason for using it in a comment. Ideally,
786
- document what types could be used.
783
+ :class: `object ` instead.
784
+
785
+ When using :ref: `Any `, document the reason for using it in a comment, unless the
786
+ reason is obvious. Ideally, document what types could be used. Obvious
787
+ reasons can include:
788
+
789
+ * Using :ref: `Any ` as a type argument for a generic with invariant type variables
790
+ to say "any object of this type is allowed", e.g. ``Future[Any] ``.
791
+ * Using ``dict[str, Any] `` or ``Mapping[str, Any] `` when the value types
792
+ depends on the keys. But consider using :ref: `TypedDict ` or
793
+ ``dict[str, Incomplete] `` (temporarily) when the keys of the dictionary are
794
+ fixed.
787
795
788
796
The ``Any `` Trick
789
797
-----------------
0 commit comments