mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-08 12:48:07 +00:00
[ty] Reduce false positives for TypedDict
types (#19354)
This commit is contained in:
parent
f3a27406c9
commit
002f9057db
8 changed files with 34 additions and 11 deletions
|
@ -245,7 +245,7 @@ class D(TypedDict):
|
|||
td = D(x=1, label="a")
|
||||
td["x"] = 0
|
||||
# TODO: should be Literal[0]
|
||||
reveal_type(td["x"]) # revealed: @Todo(TypedDict)
|
||||
reveal_type(td["x"]) # revealed: @Todo(Support for `TypedDict`)
|
||||
|
||||
# error: [unresolved-reference]
|
||||
does["not"]["exist"] = 0
|
||||
|
|
|
@ -10,8 +10,6 @@ class Person(TypedDict):
|
|||
name: str
|
||||
age: int | None
|
||||
|
||||
# TODO: This should not be an error:
|
||||
# error: [invalid-assignment]
|
||||
alice: Person = {"name": "Alice", "age": 30}
|
||||
|
||||
# Alternative syntax
|
||||
|
@ -22,6 +20,6 @@ msg = Message(id=1, content="Hello")
|
|||
# No errors for yet-unsupported features (`closed`):
|
||||
OtherMessage = TypedDict("OtherMessage", {"id": int, "content": str}, closed=True)
|
||||
|
||||
reveal_type(Person.__required_keys__) # revealed: @Todo(TypedDict)
|
||||
reveal_type(Message.__required_keys__) # revealed: @Todo(TypedDict)
|
||||
reveal_type(Person.__required_keys__) # revealed: @Todo(Support for `TypedDict`)
|
||||
reveal_type(Message.__required_keys__) # revealed: @Todo(Support for `TypedDict`)
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue