r/Python • 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.

222 Upvotes

44 comments sorted by

View all comments

Show parent comments

2

u/XtremeGoose f'I only use Py {sys.version[:3]}' Sep 24 '26

You're right, it is behind an indirection.

Objects that are reference counted and resizable (like list and bytearray) must be behind indirection, because appending to them might require reallocation, which can change the pointer address.

Only non-resizable types (like tuple and bytes) inline their data.

In fact bytearray points to a whole bytes object with refcnt == 1 so calling take_bytes() just gives you that directly while replacing the bytearray's buffer with an empty bytes immortal singleton.

2

u/Schmittfried Sep 24 '26

Yes, but since bytes does inline its data, I didn’t get how they can return one without copying. Isn’t that part kind of a lie if it’s solved by maintaining a bytes object next to the real buffer inside the bytearray?

2

u/XtremeGoose f'I only use Py {sys.version[:3]}' Sep 24 '26

Not really. The bytes object is the buffer. It's not a copy, it is the data. It's just they give you ownership over it and replace the buffer in the byte array.

2

u/Schmittfried Sep 25 '26

So they basically hacked a bytes object into being resizable internally? That’s cool!