-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected typegenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementation
Description
Summary
Seems like a bug (if I understand everything correctly) regarding type narrowing of dict with dict() interface.
from typing import Any
name: str = "hello"
d: dict[str, Any] = dict(name=name) # {"name": name} wouldn't
d["age"] = 0Triggers:
error[invalid-assignment]: Method `__setitem__` of type `bound method dict[str, str].__setitem__(key: str, value: str, /) -> None` cannot be called with a key of type `Literal["age"]` and a value of type `Literal[0]` on object of type `dict[str, str]`
--> debug.py:6:1
|
4 | name: str = "hello"
5 | d: dict[str, Any] = dict(name=name) # {"name": name} wouldn't
6 | d["age"] = 0
| ^
|
info: rule `invalid-assignment` is enabled by default
Found 1 diagnostic
Version
ty 0.0.1-alpha.17 (1712284 2025-08-06)
janosh and dmytro-GL
Metadata
Metadata
Assignees
Labels
bidirectional inferenceInference of types that takes into account the context of a declared type or expected typeInference of types that takes into account the context of a declared type or expected typegenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementation