SogoKato / typeddict-validator

Validates Python's TypedDict
MIT License
1 stars 0 forks source link

Feature request: add support for NotRequired #1

Open jennydaman opened 7 months ago

jennydaman commented 7 months ago

https://peps.python.org/pep-0655/

SebastianDix commented 1 month ago

Hello @SogoKato , if I give you a PR with support for NotRequired and Required, would you review it and merge if satisfied with it?

The issue is that sometimes the schema can be flexible, in that case one uses

from typing import NotRequired
class MySchema(TypedDict):
    age: int
    gender: NotRequired[str]

And in that case we could tell your library to also ignore this, or even give the option to enforce presence of NotRequired keys for testing purposes.

There is also Required

from typing import NotRequired
class MySchema(TypedDict, total=False):
    name: Required[str]
    age: int
    gender: str
    job: str
    hobbies: list[str]

where we have a flexible schema, but only some keys are actually required

https://docs.python.org/3/library/typing.html#typing.Required

SogoKato commented 1 month ago

Hi @SebastianDix! Thank you for your suggestion.

That sounds great! I'd be happy to review your PR.