Skip to content

Commit 91d4adc

Browse files
committed
Incorporated more feedback.
1 parent 7591a4d commit 91d4adc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

docs/spec/overload.rst

+6-7
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,15 @@ If two overloads can accept the same set of arguments, they are said
192192
to "partially overlap". If two overloads partially overlap, the return type
193193
of the former overload should be assignable to the return type of the
194194
latter overload. If this condition doesn't hold, it is indicative of a
195-
programming error and should be reported by type checkers::
196-
197-
# These overloads partially overlap because both accept an
198-
# argument of type Literal[0], but the return type int is
199-
# not assignable to str.
195+
programming error and should be reported by type checkers. The purpose of
196+
this check is to prevent unsoundness of this form::
200197

201198
@overload
202-
def func1(x: Literal[0]) -> int: ...
199+
def is_one(x: Literal[0]) -> Literal[True]: ...
203200
@overload
204-
def func1(x: int) -> str: ...
201+
def is_one(x: int) -> Literal[False]: ...
202+
203+
reveal_type(is_one(int(1))) # Reveals Literal[False], but True at runtime
205204

206205
Type checkers may exempt certain magic methods from the above check
207206
for conditions that are mandated by their usage in the runtime. For example,

0 commit comments

Comments
 (0)