These days writing a new library is sometimes faster than finding existing ones. So, I wrote a tiny cool sentinel Maybe[T] in #python

https://github.com/Fatal1ty/maybe-missing

GitHub - Fatal1ty/maybe-missing: A tiny typed sentinel for distinguishing None from not provided

A tiny typed sentinel for distinguishing None from not provided - Fatal1ty/maybe-missing

GitHub

@tikhonov_a there's already a MISSING sentinel in dataclasses, modelled after attrs.NOTHING. Consider re-exporting that?

As for patch operations, I usually use a TypedDict with total=False or NotRequired[T] fields. I find it works pretty well.

@tintvrtkovic Yeah, I know about MISSING from dataclasses. But I’m not sure re-exporting it will actually solve any problem. And AFAIR a dataclass field with that MISSING default value assigned will be interpreted as “no default value provided” by the dataclass builder. As for TypedDict, you will still need to do something like `dto.get("not_required", MISSING)` to distinguish valid None from not provided.
@tikhonov_a good point about MISSING. For the typeddict approach I just check if the key is in there, no .get()
@tintvrtkovic do you pass TypedDict objects all the way to the function which, for example, constructs database query? In this case you’ll be fine.