File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -192,16 +192,15 @@ If two overloads can accept the same set of arguments, they are said
192
192
to "partially overlap". If two overloads partially overlap, the return type
193
193
of the former overload should be assignable to the return type of the
194
194
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::
200
197
201
198
@overload
202
- def func1 (x: Literal[0]) -> int : ...
199
+ def is_one (x: Literal[0]) -> Literal[True] : ...
203
200
@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
205
204
206
205
Type checkers may exempt certain magic methods from the above check
207
206
for conditions that are mandated by their usage in the runtime. For example,
You can’t perform that action at this time.
0 commit comments