let's say I have a simple HTTP endpoint accepting JSON payload form the user:
- here the user passed
Noneexplicitly:
payload = {
"name": "Paul",
"option": None
}
- and here the user didn't provide
optionat all:
payload = {
"name": "Paul",
}
For some reason, I want to 'normalize' such payloads into
payload = {
"name": "Paul",
"option": Missing(),
}
where Missing() is an instance of a class:
class Missing:
"""Represents missing value in a dictionary"""
pass
so I can differentiate between user passing None explicitly and not passing option key at all.
What I'm struggling to define is a custom "type constructor", such that I could then annotate function argument like so:
def process_user_option(option: Missing[Optional[str]]):
...do something with 'option'
and the semantics of Missing would be something like this:
Missing(x) -> Union[Optional[x], Missing]
Any suggestions? Thank you!