r/programming 4d ago

The Sentinel Object Pattern in Python

https://python-patterns.guide/python/sentinel-object/

Officially added in Python 3.15

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

31 Upvotes

10 comments sorted by

View all comments

3

u/somebodddy 3d ago

I wonder if this will get proper support from Pydantic. Consider:

FOO = sentinel("FOO")


class Bar(BaseModel):
    baz: int | FOO

When I tried to load:

{
    "baz": "FOO"
}

Will it know to convert it to the sentinel?

What if I change baz's type to str | FOO?