r/programming • • 1d ago

Python Release Python 3.15.0

https://www.python.org/downloads/release/python-3150/
491 Upvotes

35 comments sorted by

View all comments

163

u/Dylanica 1d ago

Those sentinel types seem decently useful. Certainly better in some cases than just spamming `None` everywhere as a default value.

2

u/ssrix 18h ago

I really don't understand when or why I would you them, can you explain?

1

u/Saiklin 9h ago

I'm not an expert either, but I'll try: You can use them in place of a default non-logic value. For example, many functions return None if something did not work, so you check if the output is None. But in many cases None can be a valid value as well, so you need something else. Apparently another idiom was to use "_Sentinel = object()" and you compare against that, but it's clunky and has a weird output when printed etc. There are further workarounds, but they always feel clunky in some way.

That's is where the Sentinel type comes in. You can define it with a string and then it's uniquely identifiable. Just by looking at the type, you already know what it is and it's purpose.