Commit 735ec0c
[ty] Fix generic inference for non-dataclass inheriting from generic dataclass (#21159)
## Summary
Fixes astral-sh/ty#1427
This PR fixes a regression introduced in alpha.24 where non-dataclass
children of generic dataclasses lost generic type parameter information
during `__init__` synthesis.
The issue occurred because when looking up inherited members in the MRO,
the child class's `inherited_generic_context` was correctly passed down,
but `own_synthesized_member()` (which synthesizes dataclass `__init__`
methods) didn't accept this parameter. It only used
`self.inherited_generic_context(db)`, which returned the parent's
context instead of the child's.
The fix threads the child's generic context through to the synthesis
logic, allowing proper generic type inference for inherited dataclass
constructors.
## Test Plan
- Added regression test for non-dataclass inheriting from generic
dataclass
- Verified the exact repro case from the issue now works
- All 277 mdtest tests passing
- Clippy clean
- Manually verified with Python runtime, mypy, and pyright - all accept
this code pattern
## Verification
Tested against multiple type checkers:
- ✅ Python runtime: Code works correctly
- ✅ mypy: No issues found
- ✅ pyright: 0 errors, 0 warnings
- ✅ ty alpha.23: Worked (before regression)
- ❌ ty alpha.24: Regression
- ✅ ty with this fix: Works correctly
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: David Peter <mail@david-peter.de>1 parent 3585c96 commit 735ec0c
2 files changed
Lines changed: 39 additions & 3 deletions
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
841 | 875 | | |
842 | 876 | | |
843 | 877 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2176 | 2176 | | |
2177 | 2177 | | |
2178 | 2178 | | |
2179 | | - | |
| 2179 | + | |
| 2180 | + | |
2180 | 2181 | | |
2181 | 2182 | | |
2182 | 2183 | | |
| |||
2192 | 2193 | | |
2193 | 2194 | | |
2194 | 2195 | | |
| 2196 | + | |
2195 | 2197 | | |
2196 | 2198 | | |
2197 | 2199 | | |
| |||
2320 | 2322 | | |
2321 | 2323 | | |
2322 | 2324 | | |
2323 | | - | |
| 2325 | + | |
2324 | 2326 | | |
2325 | 2327 | | |
2326 | 2328 | | |
| |||
2702 | 2704 | | |
2703 | 2705 | | |
2704 | 2706 | | |
2705 | | - | |
| 2707 | + | |
2706 | 2708 | | |
2707 | 2709 | | |
2708 | 2710 | | |
| |||
0 commit comments