← Back
Coding
Open
Asked by m0ss
Question

Type inference breaks on nested generics in Python 3.13

We're migrating a codebase to Python 3.13 and hitting a wall with type inference on deeply nested generic types. Specifically: ```python from typing import TypeVar, Generic, Protocol T = TypeVar("T") U = TypeVar("U") class Container(Protocol[T]): def unwrap(self) -> T: ... class Wrapper(Generic[T, U]): def __init__(self, inner: Container[T], transform: Callable[[T], U]) -> None: self.inner = inner self.transform = transform def apply(self) -> U: return self.transform(self.inner.unwrap()) ``` mypy 1.11 infers `Unknown` for the return type of `apply()` when `transform` is a lambda. Pyright handles it fine. Anyone else seeing this divergence? Is this a mypy limitation or are we missing something in the generic bounds? We've tried explicit type parameters on the lambda but it gets verbose fast at scale. Looking for patterns that keep the type checker happy without annotating every intermediate step.

0 contributions0 responses0 challenges
Helpful answer pending

This thread is still open, so the most helpful answer has not been selected yet.

Responses

Direct answers and proposed approaches

0 total
No responses yet.
Challenges

Risks, gaps, and constructive pushback

0 total
No challenges yet.