Skip to content

Commit 965a9f8

Browse files
committed
it's a start
1 parent 290a572 commit 965a9f8

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

crates/ty_python_semantic/resources/mdtest/async.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ async def main():
4343
loop = asyncio.get_event_loop()
4444
with concurrent.futures.ThreadPoolExecutor() as pool:
4545
result = await loop.run_in_executor(pool, blocking_function)
46-
47-
# TODO: should be `int`
48-
reveal_type(result) # revealed: Unknown
46+
reveal_type(result) # revealed: int
4947
```
5048

5149
### `asyncio.Task`

crates/ty_python_semantic/resources/mdtest/dataclasses/fields.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def get_default() -> str:
8282

8383
reveal_type(field(default=1)) # revealed: dataclasses.Field[Literal[1]]
8484
reveal_type(field(default=None)) # revealed: dataclasses.Field[None]
85-
# TODO: this could ideally be `dataclasses.Field[str]` with a better generics solver
86-
reveal_type(field(default_factory=get_default)) # revealed: dataclasses.Field[Unknown]
85+
reveal_type(field(default_factory=get_default)) # revealed: dataclasses.Field[str]
8786
```
8887

8988
## dataclass_transform field_specifiers

crates/ty_python_semantic/resources/mdtest/decorators.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,8 @@ from functools import cache
144144
def f(x: int) -> int:
145145
return x**2
146146

147-
# TODO: Should be `_lru_cache_wrapper[int]`
148-
reveal_type(f) # revealed: _lru_cache_wrapper[Unknown]
149-
150-
# TODO: Should be `int`
151-
reveal_type(f(1)) # revealed: Unknown
147+
reveal_type(f) # revealed: _lru_cache_wrapper[int]
148+
reveal_type(f(1)) # revealed: int
152149
```
153150

154151
## Lambdas as decorators

crates/ty_python_semantic/src/types/generics.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,27 @@ impl<'db> SpecializationBuilder<'db> {
16471647
}
16481648
}
16491649

1650+
(Type::Callable(formal_callable), _) => {
1651+
if let Some(Type::Callable(actual_callable)) =
1652+
actual.try_upcast_to_callable(self.db)
1653+
{
1654+
for formal_signature in &formal_callable.signatures(self.db).overloads {
1655+
for actual_signature in &actual_callable.signatures(self.db).overloads {
1656+
if let Some(formal_return_ty) = formal_signature.return_ty
1657+
&& let Some(actual_return_ty) = actual_signature.return_ty
1658+
{
1659+
self.infer_map_impl(
1660+
formal_return_ty,
1661+
actual_return_ty,
1662+
polarity,
1663+
&mut f,
1664+
)?;
1665+
}
1666+
}
1667+
}
1668+
}
1669+
}
1670+
16501671
// TODO: Add more forms that we can structurally induct into: type[C], callables
16511672
_ => {}
16521673
}

0 commit comments

Comments
 (0)