Skip to content

Commit cdb2685

Browse files
authored
Document use of ... in overloads (#10772)
1 parent f137f11 commit cdb2685

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/source/more_types.rst

+19
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,25 @@ return type by using overloads like so:
295295
subtypes, you can use a :ref:`value restriction
296296
<type-variable-value-restriction>`.
297297

298+
The default values of a function's arguments don't affect its signature, only
299+
the absence or presence of a default value does. So in order to reduce
300+
redundancy it's possible to replace default values in overload definitions with
301+
`...` as a placeholder.
302+
303+
.. code-block:: python
304+
305+
from typing import overload
306+
307+
class M: ...
308+
309+
@overload
310+
def get_model(model_or_pk: M, flag: bool = ...) -> M: ...
311+
@overload
312+
def get_model(model_or_pk: int, flag: bool = ...) -> M | None: ...
313+
314+
def get_model(model_or_pk: int | M, flag: bool = True) -> M | None:
315+
...
316+
298317
299318
Runtime behavior
300319
----------------

0 commit comments

Comments
 (0)