Skip to content

Commit 46b938b

Browse files
committed
add failing tests
1 parent d392938 commit 46b938b

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

crates/ty_python_semantic/resources/mdtest/assignment/annotations.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ reveal_type(x) # revealed: Literal[1]
417417
python-version = "3.12"
418418
```
419419

420+
`generic_list.py`:
421+
420422
```py
421423
from typing import Literal
422424

@@ -456,6 +458,8 @@ reveal_type(j) # revealed: Literal[True]
456458

457459
The function arguments are also inferred using the type context:
458460

461+
`typed_dict.py`:
462+
459463
```py
460464
from typing import TypedDict
461465

@@ -482,6 +486,48 @@ c: TD = f([{"y": 0}, {"x": 1}])
482486
c: TD | None = f([{"y": 0}, {"x": 1}])
483487
```
484488

489+
But not in a way that leads to assignability errors:
490+
491+
`dict_any.py`:
492+
493+
```py
494+
from typing import TypedDict, Any
495+
496+
class TD(TypedDict, total=False):
497+
x: str
498+
499+
class TD2(TypedDict):
500+
x: str
501+
502+
def f(self, dt: dict[str, Any], key: str):
503+
# TODO: This should not error once typed dict assignability is implemented.
504+
# error: [invalid-assignment]
505+
x1: TD = dt.get(key, {})
506+
reveal_type(x1) # revealed: TD
507+
508+
x2: TD = dt.get(key, {"x": 0})
509+
reveal_type(x2) # revealed: Any
510+
511+
x3: TD | None = dt.get(key, {})
512+
# TODO: This should reveal `Any` once typed dict assignability is implemented.
513+
reveal_type(x3) # revealed: Any | None
514+
515+
x4: TD | None = dt.get(key, {"x": 0})
516+
reveal_type(x4) # revealed: Any
517+
518+
x5: TD2 = dt.get(key, {})
519+
reveal_type(x5) # revealed: Any
520+
521+
x6: TD2 = dt.get(key, {"x": 0})
522+
reveal_type(x6) # revealed: Any
523+
524+
x7: TD2 | None = dt.get(key, {})
525+
reveal_type(x7) # revealed: Any
526+
527+
x8: TD2 | None = dt.get(key, {"x": 0})
528+
reveal_type(x8) # revealed: Any
529+
```
530+
485531
## Prefer the declared type of generic classes
486532

487533
```toml

crates/ty_python_semantic/src/types/infer/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
32043204
default,
32053205
} = node;
32063206
if default.is_some() {
3207-
self.deferred.insert(definition);
3207+
self.deferred.insert(definition, self.multi_inference_state);
32083208
}
32093209
let identity = TypeVarIdentity::new(
32103210
self.db(),
@@ -4637,7 +4637,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
46374637
}
46384638

46394639
if default.is_some() {
4640-
self.deferred.insert(definition);
4640+
self.deferred.insert(definition, self.multi_inference_state);
46414641
}
46424642

46434643
let identity =

0 commit comments

Comments
 (0)