| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for the PR and all your work on this! Could you add documentation to the TypedDict page: https://mypy.readthedocs.io/en/stable/typed_dict.html ?
Sorry, something went wrong.
| request = make_request(*args, **kwargs) | ||
| return self.do_api_query(request) | ||
|
|
||
| # For more preise keyword typing, you can use `Unpack` along with a |
There was a problem hiding this comment.
| # For more preise keyword typing, you can use `Unpack` along with a | |
| # For more precise keyword typing, you can use `Unpack` along with a |
Sorry, something went wrong.
|
I don't think mypy enables PEP 692 by default yet, so maybe we should do that first? |
Sorry, something went wrong.
Updated and extended the docs section on mixing required non-required items in a TypedDict. Introduced the use of Required and NotRequired type qualifiers.
|
Thanks for the comments. I added the section to the TypedDict docs, also updated the section on mixing required and not required items. As for enabling Unpack - good point! Let's park the doc update for a while. I will try to go through the PEP 692 and see if its specification is enforced by mypy or if we're still missing something and create a separate PR for that. I'm going mountain hiking for a few days, will try to pick that up when I come back. |
Sorry, something went wrong.
| As a rule of thumb, if more keys of a particular ``TypedDict`` are required | ||
| than not, construct the new type with the ``total`` parameter set to ``True`` | ||
| and qualify the non required keys using ``NotRequired``. Otherwise, construct | ||
| the new type with the ``total`` parameter set to ``False`` and qualify the | ||
| required keys with ``Required``. | ||
|
|
||
| Using ``Required`` with a total ``TypedDict`` and using ``NotRequired`` with a | ||
| partial ``TypedDict`` is redundant. However, it is allowed and can be used to | ||
| qualify the required and not required keys explicitly. | ||
|
|
||
| If a particular key can accept ``None``, it is recommended to avoid mixing | ||
| ``Optional`` with either ``Required`` or ``NotRequired`` and use the | ||
| ``TYPE|None`` notation instead: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # Preferred approach. | ||
| class Car(TypedDict): | ||
| model: str | ||
| owner: NotRequired[str | None] | ||
|
|
||
| # Not recommended. | ||
| class Car(TypedDict): | ||
| model: str | ||
| owner: NotRequired[Optional[str]] |
There was a problem hiding this comment.
Let me know if this is too long. Maybe we could just link to the "How to teach this" section of the PEP 655?
Sorry, something went wrong.
|
Hey, sorry for no updates on this (the weather was too nice not to go outside). I started working on enabling the Unpack feature by default, just want to make sure that all the examples from PEP 692 are in the test suite and are passing. Hope to find some time to work on this over the weekend. |
Sorry, something went wrong.
|
I've opened another PR #15612 that's adding tests from PEP 692, still have trouble with:
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PEP 692 has been accepted and issue #4441 is fixed - added an entry to the cheatsheet mentioning a new way of annotating **kwargs in a function signature.