-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-46677: Add examples of inheritance and attributes to TypedDict
docs.
#31349
bpo-46677: Add examples of inheritance and attributes to TypedDict
docs.
#31349
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to mention PEP655 in the doc!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some high-level feedback:
- It would be good to use the formal syntax for these attributes, as we do with ParamSpec.args (https://docs.python.org/3.10/library/typing.html#typing.ParamSpec.args). That way, we can refer to the attribute definitions by name and find them more easily.
- This is going to conflict with bpo-46066: Deprecate kwargs syntax for TypedDict definitions #31126. We should probably merge that one first as it got here first :)
- Could you also mention that the functional syntax is useful for TypedDicts with keys that aren't valid identifiers?
- We can't mention PEP 655 yet because the PEP is still in draft. In the meantime, we should mention the mixed inheritance trick to make a TypedDict with some required and non-required keys.
And cc @davidfstr in case you'd also like to give some feedback here.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! @gvanrossum I'm planning to merge this docs enhancement for TypedDict.
Thanks @CharlieZhao95 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Sorry @CharlieZhao95 and @JelleZijlstra, I had trouble checking out the |
Sorry, @CharlieZhao95 and @JelleZijlstra, I could not cleanly backport this to |
@CharlieZhao95 do you want to do the backports manually? Probably just need to fix some small conflicts. |
Thanks @CharlieZhao95 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry @CharlieZhao95 and @JelleZijlstra, I had trouble checking out the |
Sure. It won't take long, I will finish it soon. 😉 |
…docs (pythonGH-31349) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 8a207e0)
GH-31808 is a backport of this pull request to the 3.9 branch. |
…dDict` docs (pythonGH-31349) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 8a207e0) Co-authored-by: Charlie Zhao <68189100+CharlieZhao95@users.noreply.github.com>
GH-31815 is a backport of this pull request to the 3.10 branch. |
…Dict` docs. (pythonGH-31349) (pythonGH-31808) * bpo-46677: Add examples of inheritance and attributes to `TypedDict` docs (pythonGH-31349) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 8a207e0)
Add examples of inheritance and attributes to
TypedDict
docs.https://bugs.python.org/issue46677