Support for Partial types
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
File t.py:
from typing_extensions import TypedDict
class Foo(TypedDict):
x:int
y:int
foo: Partial[Foo] = {'x': 1}
# reveal_type(foo) -> TypedDict('t.Foo?', {'x'?: builtins.int, 'y'?: builtins.int})
Pitch
For some uses cases, e.g. processing PATCH requests on a web server, we usually want to allow a partial version of the original model. Currently this must be done manually, and that can be a bit error prone since one may forget to update the partial model. The Partial type annotation would transform the original type into its optional version.
Related to: https://github.com/python/mypy/issues/4128
Note: Examples taken from https://stackoverflow.com/questions/69091758/python-typehint-subsetpartial-of-an-typeddict
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the t.py example and the related issue #4128 to understand the proposed Partial behavior for TypedDict. Done means the annotation accepts partial Foo values and reveal_type(foo) shows optional x and y fields as specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100