Skip to content

Commit aac97d0

Browse files
committed
more detail
1 parent 68c6e30 commit aac97d0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/source/error_code_list.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,16 @@ Warn if multiple ``@overload`` variants overlap in unsafe ways.
11371137
def takes_a(a: A) -> str:
11381138
return foo(a)
11391139
1140-
assert isinstance(takes_a(B()), str) # may fail when run
1140+
a: A = B()
1141+
value = takes_a(a)
1142+
# mypy will think that value is a str, but it could actually be an int
1143+
reveal_type(value) # Revealed type is "builtins.str"
1144+
1145+
1146+
Note that in cases you ignore this error, mypy will usually still infer the
1147+
types you expect.
1148+
1149+
See :ref:`overloading <function-overloading>` for more explanation.
11411150

11421151
.. _code-annotation-unchecked:
11431152

docs/source/more_types.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ To prevent these kinds of issues, mypy will detect and prohibit inherently unsaf
501501
overlapping overloads on a best-effort basis. Two variants are considered unsafely
502502
overlapping when both of the following are true:
503503

504-
1. All of the arguments of the first variant are compatible with the second.
504+
1. All of the arguments of the first variant are potentially compatible with the second.
505505
2. The return type of the first variant is *not* compatible with (e.g. is not a
506506
subtype of) the second.
507507

@@ -510,6 +510,9 @@ the ``object`` argument in the second, yet the ``int`` return type is not a subt
510510
``str``. Both conditions are true, so mypy will correctly flag ``unsafe_func`` as
511511
being unsafe.
512512

513+
Note that in cases you ignore the overlapping overload error, mypy will usually
514+
still infer the types you expect at callsites.
515+
513516
However, mypy will not detect *all* unsafe uses of overloads. For example,
514517
suppose we modify the above snippet so it calls ``summarize`` instead of
515518
``unsafe_func``:

0 commit comments

Comments
 (0)