Germán Méndez Bravo <german...@gmail.com> added the comment:

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 <rep...@bugs.python.org> wrote:
> 
> 
> Nils Kattenbeck <nilskem...@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 <rep...@bugs.python.org>
> <https://bugs.python.org/issue41249>
> _______________________________________

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41249>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to