We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4bdf0db commit 45dee4fCopy full SHA for 45dee4f
docs/source/best_practices.rst
@@ -44,12 +44,21 @@ No::
44
Ergonomic Practices
45
===================
46
47
-Using `Any`
48
------------
+Using ``Any`` and ``object``
+----------------------------
49
50
Generally, use ``Any`` when a type cannot be expressed appropriately
51
with the current type system or using the correct type is unergonomic.
52
53
+If a function accepts every possible object as an argument, for example
54
+because it's only passed to ``str()``, use ``object`` instead of ``Any`` as
55
+type annotation. Similarly, if the return value of a callback is ignored,
56
+annotate it with ``object``::
57
+
58
+ def call_cb_if_int(cb: Callable[[int], object], o: object) -> None:
59
+ if isinstance(o, int):
60
+ cb(o)
61
62
Arguments and Return Types
63
--------------------------
64
0 commit comments