Skip to content

Commit 1a7e9df

Browse files
committed
Clarifying comment (and additional test) as to why we union with Unknown
1 parent 6e5af88 commit 1a7e9df

File tree

1 file changed

+10
-0
lines changed
  • crates/red_knot_python_semantic/resources/mdtest/binary

1 file changed

+10
-0
lines changed

crates/red_knot_python_semantic/resources/mdtest/binary/instances.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ class B:
262262
reveal_type(B() + B()) # revealed: Unknown | int
263263
```
264264

265+
Note that we union with `Unknown` here because `__add__` is not declared. We do infer just `int` if
266+
the callable is declared:
267+
268+
```py
269+
class B2:
270+
__add__: A = A()
271+
272+
reveal_type(B2() + B2()) # revealed: int
273+
```
274+
265275
## Integration test: numbers from typeshed
266276

267277
We get less precise results from binary operations on float/complex literals due to the special case

0 commit comments

Comments
 (0)