Fixed required/optional keys with old-style TypedDict#778
Fixed required/optional keys with old-style TypedDict#778JelleZijlstra merged 3 commits intopython:masterfrom domdfcoding:issue-761
Conversation
| pass | ||
|
|
||
| return _TypedDictMeta(typename, (), ns) | ||
| return _TypedDictMeta(typename, (), ns, total=total) |
There was a problem hiding this comment.
On Python 3.4 and 3.5 it seems that _TypedDictMeta(...) calls __init__ rather than __new__, but __init__ isn't implemented. See, for instance: https://travis-ci.com/github/python/typing/jobs/473002561#L338
There was a problem hiding this comment.
That looks nasty. I wonder if it's related to this note in https://docs.python.org/3/whatsnew/3.6.html#changes-in-the-python-api :
As part of PEP 487, the handling of keyword arguments passed to type (other than the metaclass hint, metaclass) is now consistently delegated to object.init_subclass(). This means that type.new() and type.init() both now accept arbitrary keyword arguments, but object.init_subclass() (which is called from type.new()) will reject them by default. Custom metaclasses accepting additional keyword arguments will need to adjust their calls to type.new() (whether direct or via super) accordingly.
I just tried and failed to get pyenv to compile 3.5 for me so I can't try this out myself :( If it's too hard to get this to work I wouldn't be opposed to fixing it for 3.6+ only for now.
|
There aren't any tests set up on Travis for Python 3.9, but for me they fail locally as python/cpython#22736 didn't make it into 3.9.1. |
JelleZijlstra
left a comment
There was a problem hiding this comment.
Sorry for the long wait here! I just merged a PR adding 3.9.0 to CI. I think it's OK to make typing_extensions.TypedDict not an alias for typing.TypedDict in 3.9.0/1, so that we can provide the fixed version of TypedDict here.
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
|
Right, I think I've sorted it. On Python 3.9.2 and above For Python 3.4 and 3.5 it is necessary to implement |
Fixes #761
Copied from python/cpython#22736
Co-authored-by: Alex Grönholm alex.gronholm@nextday.fi