File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 4444Ergonomic Practices
4545===================
4646
47- Using `Any `
48- -----------
47+ Using `` Any `` and `` object ` `
48+ ----------------------------
4949
5050Generally, use ``Any `` when a type cannot be expressed appropriately
5151with the current type system or using the correct type is unergonomic.
5252
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+
5362Arguments and Return Types
5463--------------------------
5564
You can’t perform that action at this time.
0 commit comments