From 91d4adce96eee9bb4b9266a2ca78bcb9a3ee5080 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 28 Aug 2024 19:42:53 -0700 Subject: [PATCH] Incorporated more feedback. --- docs/spec/overload.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/spec/overload.rst b/docs/spec/overload.rst index 5a70d298..6e574dca 100644 --- a/docs/spec/overload.rst +++ b/docs/spec/overload.rst @@ -192,16 +192,15 @@ If two overloads can accept the same set of arguments, they are said to "partially overlap". If two overloads partially overlap, the return type of the former overload should be assignable to the return type of the latter overload. If this condition doesn't hold, it is indicative of a -programming error and should be reported by type checkers:: - - # These overloads partially overlap because both accept an - # argument of type Literal[0], but the return type int is - # not assignable to str. +programming error and should be reported by type checkers. The purpose of +this check is to prevent unsoundness of this form:: @overload - def func1(x: Literal[0]) -> int: ... + def is_one(x: Literal[0]) -> Literal[True]: ... @overload - def func1(x: int) -> str: ... + def is_one(x: int) -> Literal[False]: ... + + reveal_type(is_one(int(1))) # Reveals Literal[False], but True at runtime Type checkers may exempt certain magic methods from the above check for conditions that are mandated by their usage in the runtime. For example,