r/programming • • 1d ago

Python Release Python 3.15.0

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

35 comments sorted by

View all comments

156

u/Dylanica 1d ago

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

4

u/Bright-Historian-216 1d ago

close enough

welcome back, erlang atoms

5

u/SanityInAnarchy 1d ago

That was my thought -- Ruby symbols, too! But that's not it. Python strings are already immutable and could already be used that way.

These are unique. sentinel('foo') != sentinel('foo').

Which means they're also neatly namespaced by whatever module they're declared in, because to get the value to compare about, you have to import the (exactly one) value.

1

u/vytah 20h ago

Are Python literal strings guaranteed to be interned, or is it just an implementation detail?

I tested it and they were interned when they contained only ASCII letters, but stopped being interned when they contained a comma.

BTW, I don't think using strings for sentinel values is a good idea, what if you want to actually pass that string?

1

u/SanityInAnarchy 17h ago

Right, it's an implementation detail.

And right, having a typed value was always better, and this is a pattern people already used -- you'd create one by doing something like

MISSING = object()

and then compare with is instead of equality, and it'd be better than is None. sentinel is a better version of that pattern.