Commit c71fdb0
Fixes gh-20512
This PR fixes a bug where calling .update() on a specialized generic
TypedDict like Group[int] would fail type checking because the plugin
reverted to the unspecialized definition (Group[ValT]).
After a lot of dead ends this one wasn't as straightforward as I thought
initially. After spending a lot of time in `checkmember.py` and
`checkexpr.py`I finally found the issue in `mypy/plugins/default.py`.
The call got the anonymous version of the TypedDict from the TypeInfo,
which pointed back to the original generic declaration. This caused
specialized types to be replaced by their original TypeVar placeholders
during the signature construction for update(). Whew!
The fix basically uses `ctx.type` (the specialized type of TypedDict
being updated) as the source for the items, then applies the anonymous
fallback and sets `required_keys` to an empty set to keep the correct
behavior of the update method.
Added a test in `check-typeddict.test` which seemed like the right
place. All tests pass, as well as the original repro script from the
linked issue.
---------
Co-authored-by: Aaron Wieczorek <woz@Aarons-MacBook-Pro.local>
Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
1 parent c41dbd0 commit c71fdb0
File tree
5 files changed
+41
-11
lines changed- mypy
- plugins
- test-data/unit
5 files changed
+41
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
816 | 816 | | |
817 | 817 | | |
818 | 818 | | |
819 | | - | |
| 819 | + | |
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1263 | 1263 | | |
1264 | 1264 | | |
1265 | 1265 | | |
1266 | | - | |
| 1266 | + | |
1267 | 1267 | | |
1268 | 1268 | | |
1269 | 1269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
483 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
484 | 485 | | |
485 | 486 | | |
486 | 487 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3080 | 3080 | | |
3081 | 3081 | | |
3082 | 3082 | | |
3083 | | - | |
| 3083 | + | |
3084 | 3084 | | |
3085 | | - | |
| 3085 | + | |
3086 | 3086 | | |
3087 | | - | |
| 3087 | + | |
3088 | 3088 | | |
3089 | 3089 | | |
3090 | 3090 | | |
| |||
3110 | 3110 | | |
3111 | 3111 | | |
3112 | 3112 | | |
3113 | | - | |
3114 | | - | |
3115 | | - | |
3116 | | - | |
3117 | 3113 | | |
3118 | 3114 | | |
3119 | 3115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3011 | 3011 | | |
3012 | 3012 | | |
3013 | 3013 | | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| 3039 | + | |
| 3040 | + | |
| 3041 | + | |
| 3042 | + | |
| 3043 | + | |
| 3044 | + | |
| 3045 | + | |
| 3046 | + | |
3014 | 3047 | | |
3015 | 3048 | | |
3016 | 3049 | | |
| |||
0 commit comments