Change inference

This commit is contained in:
David Peter
2025-06-04 14:49:41 +02:00
parent e9b1fc3942
commit 7684e23612
5 changed files with 41 additions and 17 deletions

View File

@@ -138,3 +138,12 @@ def get_name() -> str:
# error: [invalid-type-alias-type] "The name of a `typing.TypeAlias` must be a string literal"
IntOrStr = TypeAliasType(get_name(), int | str)
```
## Recursive type aliases
```py
type Recursive = dict[str, "Recursive"]
# TODO: this should not be an error
r: Recursive = {"key": {}} # error: [invalid-assignment]
```

View File

@@ -396,10 +396,11 @@ type LiteralInt = TypeOf[int]
type LiteralStr = TypeOf[str]
type LiteralObject = TypeOf[object]
assert_type(bool, LiteralBool)
assert_type(int, LiteralInt)
assert_type(str, LiteralStr)
assert_type(object, LiteralObject)
# TODO: these should not be errors
assert_type(bool, LiteralBool) # error: [type-assertion-failure]
assert_type(int, LiteralInt) # error: [type-assertion-failure]
assert_type(str, LiteralStr) # error: [type-assertion-failure]
assert_type(object, LiteralObject) # error: [type-assertion-failure]
# bool
@@ -462,9 +463,10 @@ type LiteralBase = TypeOf[Base]
type LiteralDerived = TypeOf[Derived]
type LiteralUnrelated = TypeOf[Unrelated]
assert_type(Base, LiteralBase)
assert_type(Derived, LiteralDerived)
assert_type(Unrelated, LiteralUnrelated)
# TODO: these should not be errors
assert_type(Base, LiteralBase) # error: [type-assertion-failure]
assert_type(Derived, LiteralDerived) # error: [type-assertion-failure]
assert_type(Unrelated, LiteralUnrelated) # error: [type-assertion-failure]
static_assert(is_subtype_of(LiteralBase, type))
static_assert(is_subtype_of(LiteralBase, object))