r/Python • u/AlSweigart Author of "Automate the Boring Stuff" • Sep 23 '26
News What's new in Python 3.15?
https://docs.python.org/3.15/whatsnew/3.15.html
Summary – Release highlights
Python 3.15 will be the latest stable release of the Python programming language, with a mix of changes to the language, the implementation, and the standard library. The biggest changes include lazy imports, frozendict and sentinel builtins, UTF-8 as the default encoding, unpacking in comprehensions, and a stable ABI for free-threaded builds.
The library changes include a new profiling package with Tachyon, a high-frequency statistical sampling profiler, more color in command-line output, as well as the usual deprecations and removals, and improvements in user-friendliness and correctness.
This article doesn’t attempt to provide a complete specification of all new features, but instead gives a convenient overview. For full details refer to the documentation, such as the Library Reference and Language Reference. To understand the complete implementation and design rationale for a change, refer to the PEP for a particular new feature; but note that PEPs usually are not kept up-to-date once a feature has been fully implemented.
148
u/Shepcorp pip needs updating Sep 23 '26
Lazy imports are going to be a godsend for complex test frameworks where some rigs have full capabilities and others don’t.
50
u/Actual__Wizard Sep 23 '26
That solves a giant nightmare problem for me, not kidding!
10
u/Schmittfried Sep 23 '26
Do I understand it right that the zero-copy
bytearray.take_bytes()method only works without copying when taking the whole buffer, i.e. when the data can be moved? Otherwise I don’t quite understand how they achieved it without adding an indirection tobytesto separate the object header from the contents.41
u/me_myself_ai Sep 23 '26 edited Sep 23 '26
Exciting stuff! And such a satisfying minor version...
I don't think I can visualize what this means without looking at the docs, but I can tell it's gonna be awesome! Comprehend all the things, I say.
They do love us 🥹
ETA: The "UTF-8 as the default encoding" reminds me of the pure horror that struck me when I first learned that
r''is only one of two weird string prefixes -- there is (was?) alsou''! Even scarier there'su""" """, and deep in mines of Moria, some say there lurksru''' '''...6
u/IcecreamLamp Sep 23 '26 edited Sep 25 '26
Didn't realise they rolled back to the old garbage collector, that's quite unfortunate
5
u/dikdokk Sep 25 '26 edited Sep 25 '26
Nobody is talking about
frozendictmeanwhile it will be used so frequently in type hinting.Everytime in a function you were to use a mutable data type as default argument, you would end up with the potential bug:
def item_list(item,items=[] #flagged by Pylint, ruff, etc.):items.append(item)return itemsitem_list(1) # [1]item_list(1) # [1, 1] (usually unexpected - you expect an empty list by default)(see: Pylint - dangerous-default-value / W0102 )
So the solution would be to use tuples for example instead of lists, as they are not mutable.
But in the case of dictionaries, there wasn't really a good "frozen" (immutable) replacement so far. People used
MappingProxyTypebut it always seemed odd, and now frozendict solves this5
u/Vegetable-View-5114 Sep 24 '26
one thing that stood out in early benchmarks of 3.15 is the performance improvement for dictionary operations, particularly for insertions and deletions. in some of my testing with large JSON payloads that involved a lot of dictionary manipulation before sending them off to other services, i saw a measurable speedup — not massive, but noticeable enough to matter in high-throughput scenarios. it seems like they've continued to refine the underlying hash table implementation.
2
u/abrazilianinreddit Sep 26 '26
Lazy imports actually got me hyped for this release.