Python 3.15.0 was just released!
To celebrate, I'm doing 15 days of Python 3.15.
Each week day, I'll write about a new Python 3.15 feature.
We'll cover lazy imports, the new built-ins, the DX improvements, some new stdlib niceties, and MUCH more.
I'll collect my posts here π
I can't remember Python before this.
Before Python underlined the part of the line that raised the error.
Who remembers what Python version this was added on?
What do you do when you can't use `None` as the default?
You can use `object()`...
Or a singleton class...
Or another workaround...
And all these hacks had flaws.
That's why Python 3.15 introduced the built-in `sentinel`.
You can use it to create placeholder values π
Python 3.15.0 was just released!
To celebrate, I'm doing 15 days of Python 3.15.
Each week day, I'll write about a new Python 3.15 feature.
We'll cover lazy imports, the new built-ins, the DX improvements, some new stdlib niceties, and MUCH more.
I'll collect my posts here π
Python startup times just got faster.
In 3.15, you can use the keyword `lazy` to make a lazy import (`math` and `Path` below).
Lazily imported modules are only loaded
WHEN they're used, and
IF they're used.
Use them to defer loading of modules that may not be required.
What do you do when you can't use `None` as the default?
You can use `object()`...
Or a singleton class...
Or another workaround...
And all these hacks had flaws.
That's why Python 3.15 introduced the built-in `sentinel`.
You can use it to create placeholder values π
There are many benefits to using `sentinel`.
One of them is that typing sentinels is much cleaner than typing any of the alternatives.
That's because sentinels can be used as their own type.
Just like `None` can π
@willmcgugan Yeah, I know. And just today I used Textual-inspired examples to teach descriptors and `__new__`.
And the other day I used it as an example of where the new `sentinel` would come in really handy https://t.co/7f273CiKze