News: 1696329853

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

And now for something completely different: Python 3.12

(2023/10/03)


Python 3.12, the latest stable release of the Python programming language, was released on Monday, offering developers a handful of new capabilities and the removal of some cruft.

The revision arrives almost a year after the previous stable release, Python 3.11.

Python has recently been ranked the [1]most popular , [2]second [3]most popular, or [4]third most popular programming language, depending on whom you ask. Whatever the case, it's the lingua franca of data science and AI, and a common entry point into programming in academic settings.

[5]

The [6]3.12 release includes more accommodating f-strings, as was proposed in the Python Enhancement Proposal (PEP) [7]701 .

[8]

[9]

An [10]f-string , or formatted string literal, is a string literal prefixed by an 'f' – upper or lowercase – such that it can contain replacement fields within curly braces that get evaluated at run time. Most programming languages have something of the sort and with PEP 701, expression components within an f-string can be any valid Python expression. They can now handle multi-line expressions, comments, backslashes, and Unicode escape sequences.

PEP [11]695 offers an improved type parameter syntax that makes type variables easier to understand. It allows developers to declare type parameters "at a natural place within a class, function, or type alias declaration statement."

[12]

Python implements a Global Interpreter Lock, or [13]GIL , that prevents multiple Python threads from executing at the same time. The GIL is set to become optional [14]in the next version of Python 3.13 because it hinders concurrency – it's a safety bottleneck that blocks other threads.

In this release, Python has introduced a per-interpreter GIL with PEP [15]684 . It allows the creation of sub-interpreters, which makes it easier to work with multiple CPU cores. Initially, this must be done with a C API, though a Python API is planned for 3.13. One of the potential use cases would be running sub-interpreters concurrently and accessing the shared state in a thread-safe C++ library.

[16]From browser brat to backend boss: Will WASM win the web wars?

[17]This profiler chatbot promises to help speed up your Python – we can believe it

[18]Microsoft teases Python scripting in Excel

[19]Sneaky Python package security fixes help no one – except miscreants

The latest Python update also arrives with support for [20]PEP 669 , a new API for profilers, debuggers, and other monitoring tools. PEP 669 is supposed to be "low-impact," so it can be implemented in code without significant overhead – debuggers and profilers have been known to slow code down by an order of magnitude.

"We have been following and are looking at incorporating some of the modifications made as part of PEP 669 to improve the performance of monitoring," University of Massachusetts Amherst computer science professor Emery Berger told The Register . Berger also noted that [21]SlipCover – a near zero-overhead Python code coverage tool that he and graduate student Juan Altmayer Pizzorno developed – served as inspiration for PEP 669.

Berger, Pizzorno, and another graduate student, Sam Stern, also developed a Python profiler called [22]Scalene . And Berger said he and his students are exploring how they can add some of the Python 3.12 changes into their existing projects.

[23]

"We plan to use [PEP 669] to further reduce the overhead of Scalene's line-level tracking of memory usage, especially for some pathological cases," said Berger. "No surprise, given SlipCover was used as justification for the PEP, we are looking at using it to streamline and future-proof the implementation of SlipCover."

Other Python 3.12 improvements include [24]PEP 688 , which makes the buffer protocol – a way to access the underlying memory of an object – accessible via a Python API instead of just a C API, and [25]PEP 709 , which adds a compiler optimization called inlining to list, dictionary, and set comprehensions for improved performance.

Also, there are some type hint improvements, for those who prefer to be explicit about Python data types ( [26]PEP 692 and [27]PEP 698 ). And [28]error messages have been improved.

Finally, beyond the various [29]module enhancements , a slew of older features were [30]removed after several years in deprecation purgatory. All the details are available in the [31]online documentation . ®

Get our [32]Tech Resources



[1] https://www.tiobe.com/tiobe-index/

[2] https://redmonk.com/sogrady/2023/05/16/language-rankings-1-23/

[3] https://octoverse.github.com/2022/top-programming-languages

[4] https://survey.stackoverflow.co/2023/#technology

[5] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/devops&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2ZRw6pXFaZYedwohOt0hGjwAAABY&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[6] https://pythoninsider.blogspot.com/2023/10/python-3120-final-now-available.html

[7] https://docs.python.org/3.12/whatsnew/3.12.html#whatsnew312-pep701

[8] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/devops&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44ZRw6pXFaZYedwohOt0hGjwAAABY&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[9] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/devops&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33ZRw6pXFaZYedwohOt0hGjwAAABY&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[10] https://docs.python.org/3.12/reference/lexical_analysis.html#f-strings

[11] https://docs.python.org/3.12/whatsnew/3.12.html#whatsnew312-pep695

[12] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/devops&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44ZRw6pXFaZYedwohOt0hGjwAAABY&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[13] https://docs.python.org/3.12/glossary.html#term-global-interpreter-lock

[14] https://peps.python.org/pep-0703/

[15] https://peps.python.org/pep-0684/

[16] https://www.theregister.com/2023/09/01/web_assembly_wasm_column/

[17] https://www.theregister.com/2023/08/30/scalene_ai_advice_python/

[18] https://www.theregister.com/2023/08/22/python_excel_anaconda/

[19] https://www.theregister.com/2023/07/26/python_silent_security_fixes/

[20] https://peps.python.org/pep-0669/

[21] https://github.com/plasma-umass/slipcover

[22] https://github.com/plasma-umass/scalene

[23] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/devops&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33ZRw6pXFaZYedwohOt0hGjwAAABY&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[24] https://peps.python.org/pep-0688/

[25] https://peps.python.org/pep-0709/

[26] https://peps.python.org/pep-0692/

[27] https://peps.python.org/pep-0698/

[28] https://docs.python.org/3.12/whatsnew/3.12.html#improved-error-messages

[29] https://docs.python.org/3.12/whatsnew/3.12.html#improved-modules

[30] https://docs.python.org/3.12/whatsnew/3.12.html#removed

[31] https://docs.python.org/3.12/

[32] https://whitepapers.theregister.com/



b0llchit

I'm holding out for Friday Python 3.13. Rumour has it that it will be written in Snake and strangles the competition when bits come to byte.

Version 1.0

"What the hell difference does it make, Python 3.13, Python 3.12, or FORTRAN? There were good programmers lost on both sides." - A Brendan Behan quote updated just like Python these days.

MontyMole

You would be better waiting for Pithon 3.14 with support for circular references.

b0llchit

You'll need to wait at least for femto-patch-level 3.14159265358979. Rounding errors error rounding the rounds on error rounding the rounds on error rounding the rounds on error rounding the rounds on error rounding the rounds on error rounding the rounds on error rounding the rounds...

karlkarl

Indeed.

I find it worrying how so few Python developers know about weakref, so leaks in Python libraries are rampant! If we can sidestep that with a GC, I think the Python ecosystem will actually receive a "memory boost"!

bazza

After all these decades there's still a GIL...

Anonymous Coward

The GIL is part of CPython but not Jython or IronPython.

concurrency is not parallelism

wrp

The GIL makes parallelism difficult, but it has no impact on concurrency.

In Lexington, Kentucky, it's illegal to carry an ice cream cone in your pocket.