This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Kronuz
Recipients Kronuz, Nils Kattenbeck, gvanrossum, keithblaha, kj, levkivskyi
Date 2021-07-03.21:47:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <456DB7C6-55CD-4329-AB6E-813D580F09E6@gmail.com>
In-reply-to <1625344977.55.0.793156378681.issue41249@roundup.psfhosted.org>
Content
Nils, unfortunately, fixing the MRO here won’t fix the issue because `TypedDict.__annotations__` in the class copies the annotations from the parent classes, and when the type evaluation is made, it’s made using the copied annotation found in the bottommost class (which is thus then expected to be a forward reference in the same module as the class that inherited them. This producing the exact same problem of missing type.

The most likely reason for incomplete MRO is that `TypeDict` extends a class’ `__annotations__` with all of it’s parent’s `__annotations__`, so the final class has the complete set of annotations of all of its parents, so having the full inheritance chain made less sense, after all the final dictionary class has all the annotations.

> On Jul 3, 2021, at 13:43, Nils Kattenbeck <report@bugs.python.org> wrote:
> 
> 
> Nils Kattenbeck <nilskemail@gmail.com> added the comment:
> 
>> The way I fixed this is I added `__forward_module__` to `typing.ForwardRef`, so that it can resolve the forward reference with the same globals as the ones specified by the module in `__forward_module__`. `TypedDict`'s metaclass should then pass the dictionary’s module name to the annotations’ forward references via the added `module`’s keyword argument in `typing._type_check()`. I can work in a pull request with this solution and discuss any potential problems.
> 
> While this seems like a good solution I would still like to figure out why TypedDict do not preserve MRO. Because for now I have not found a reason nor did someone on the typing-sig mailinglist have a clue. Should there (no longer) be a reason for this then this problem has a trivial solution (just re-add the MRO and use that).
> 
> ----------
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue41249>
> _______________________________________
History
Date User Action Args
2021-07-03 21:47:21Kronuzsetrecipients: + Kronuz, gvanrossum, levkivskyi, Nils Kattenbeck, keithblaha, kj
2021-07-03 21:47:21Kronuzlinkissue41249 messages
2021-07-03 21:47:21Kronuzcreate