Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFix required and optional keys inheritance for TypedDict #700
Conversation
|
Should this also be updated upstream in CPython? |
|
LGTM except I wish to rename |
| class Cat(Animal): | ||
| fur_color: str | ||
| tail: int |
gvanrossum
Feb 11, 2020
Member
This isn't allowed by mypy (you can't change the type of an attribute in a subclass) so I recommend deleting the tail attribute altogether.
This isn't allowed by mypy (you can't change the type of an attribute in a subclass) so I recommend deleting the tail attribute altogether.
vemel
Feb 11, 2020
Author
Contributor
Makes sense, deleting it. I also will not remove conflicting keys from __required_keys__ and __optional_keys__ since conflicts are not allowed.
Makes sense, deleting it. I also will not remove conflicting keys from __required_keys__ and __optional_keys__ since conflicts are not allowed.
vemel
Feb 11, 2020
Author
Contributor
Pushed changes, updated tests.
Pushed changes, updated tests.
| @@ -436,6 +436,17 @@ class LabelPoint2D(Point2D, Label): ... | |||
| class Options(TypedDict, total=False): | |||
| log_level: int | |||
| log_path: str | |||
| class _Animal(TypedDict): | |||
gvanrossum
Feb 11, 2020
Member
I don't see a reason for this class name to start with _ -- maybe rename to BaseAnimal?
I don't see a reason for this class name to start with _ -- maybe rename to BaseAnimal?
vemel
Feb 11, 2020
Author
Contributor
I am not aware of a convention how to name TypedDict that has both required and optional keys. Usually I prefix a TypedDict with required keys with an underscore.
I am not aware of a convention how to name TypedDict that has both required and optional keys. Usually I prefix a TypedDict with required keys with an underscore.
vemel
Feb 11, 2020
Author
Contributor
Renamed to BaseAnimal.
Renamed to BaseAnimal.
|
Travis CI build failed for Python 3.5.1, but it looks unrelated. File "/home/travis/virtualenv/python3.5.1/lib/python3.5/site-packages/importlib_metadata/__init__.py", line 9, in <module>
import zipp
ImportError: No module named 'zipp'Probably restarting Travis build will help. |
|
Thanks! I will land this despite the 3.5.1 failure. |
|
@vemel - I think this should go upstream, as a follow-up to python/cpython#17214, since CPython is still using the pre-this-PR logic. |
|
Yes, please open a good issue and submit a PR.
On Mon, May 4, 2020 at 05:26 Zac Hatfield-Dodds ***@***.***> wrote:
@vemel <https://github.com/vemel> - I think this *should* go upstream, as
a follow-up to python/cpython#17214
<python/cpython#17214>, since CPython is still
using the pre-this-PR logic.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#700 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWCWMWTHUVAENLMQLFPULLRP2X6BANCNFSM4KRQAMPA>
.
--
--Guido (mobile)
|
|
@Zac-HD Did you submit a PR to CPython for this? Having trouble finding it. |
|
According to https://github.com/python/cpython/pulls?q=is%3Apr+author%3AZac-HD I didn't, and remembering what May was like I believe it. If you'd like to, go for it |


I realized that the inheritance of TypedDict does not work as it should.
I would assume that
Catshould have required keysnameandfur_colorand optionalvoice.But in reality, it will have required
fur_colorand optionalnameandvoice, becauseAnimalhastotal=FalseFixed
__required_keys__and__optional_keys__are copied from base classesTypedDictannotations are added to__annotations__after base annotationsTypedDictredefines them