iBet uBet web content aggregator. Adding the entire web to your favor.
iBet uBet web content aggregator. Adding the entire web to your favor.



Link to original content: https://lwn.net/Articles/946189/
Python 3.12 released [LWN.net]
|
|
Subscribe / Log in / New account

Python 3.12 released

Version 3.12 of the Python programming language has been released. The "What’s New In Python 3.12" page has plenty of details. Highlights of the release include isolated subinterpreter support, more improvements to error messages, more flexible f-strings, Linux perf support for profiling, and lots more.

to post comments

Python 3.12 released

Posted Oct 3, 2023 10:02 UTC (Tue) by whoami (guest, #166229) [Link] (5 responses)

Why do programming languages have to be all political nowadays?

Python 3.12 released

Posted Oct 3, 2023 10:10 UTC (Tue) by mb (subscriber, #50428) [Link] (2 responses)

Can you please explain what you are referring to?

Python 3.12 released

Posted Oct 3, 2023 12:45 UTC (Tue) by excors (subscriber, #95769) [Link] (1 responses)

I expect they're referring to the poem at the bottom of https://www.python.org/downloads/release/python-3120/

Python 3.12 released

Posted Oct 4, 2023 4:20 UTC (Wed) by alexeiz (guest, #95579) [Link]

The guy who wrote the poem doesn't even have anything to do with Python. Just a random political activist.

Python 3.12 released

Posted Oct 3, 2023 13:03 UTC (Tue) by Wol (subscriber, #4433) [Link]

Because political with small "p" is an inescapable fact of life? Unless, of course, you choose to go and live on a desert island (and even there, you have the problem of uninvited visitors).

Cheers,
Wol

Python 3.12 released

Posted Oct 3, 2023 13:33 UTC (Tue) by farnz (subscriber, #17727) [Link]

Because, when you rip off all the layers of meaning, "political" means "the way people treat labelled groups of people", and programming languages are all about the way people treat one labelled group of people - programmers.

Python 3.12 released

Posted Oct 3, 2023 14:00 UTC (Tue) by anarcat (subscriber, #66354) [Link] (7 responses)

I'm not a fan of:
f"This is the playlist: {", ".join(songs)}"
To me, this reads as f"foo" then a comma, then another string. In fact, this is a parse error in earlier Python, but I think that was actually a *good* thing. Now it seems the parser will just start huting for a matching bracket in a random quote following the f-string, isn't that error-prone if not downright dangerous?

Python 3.12 released

Posted Oct 3, 2023 16:07 UTC (Tue) by NYKevin (subscriber, #129325) [Link] (5 responses)

> Now it seems the parser will just start huting for a matching bracket in a random quote following the f-string, isn't that error-prone if not downright dangerous?

No, it isn't, because there's no "in a random quote" rule. The matching bracket does not have to be quoted, and in fact it is an error to quote it. Officially, f"FOO{expr}BAR" is parsed into these parts:

f"
FOO
{expr}
BAR
"

expr is interpreted as if it is not inside of any quoted context (the braces temporarily "cancel" the enclosing quotes). But in practice, you could just as validly interpret it like this:

f"FOO{
expr
}BAR"

In other words, you *could* think of the braces as matching (and temporarily "closing") the quotes, even though they formally don't, because it turns out that that produces the same overall behavior (provided the braces are also properly balanced). This also works for nested contexts like f"FOO{f"bar{"BAZ"}qux"}THE_END":

f"FOO{
f"bar{
"BAZ"
}qux"
}THE_END"

(This is a very silly example, because you could just concatenate all of the string literals and write one big string literal instead.)

However, the opening and closing quotes do have to match, so you can't write f"FOO{expr}BAR' (the single quote does not match the double quote). If you want to think of the left brace as temporarily closing the quote, then the right brace should be considered to reopen the same quote (rather than opening a brand-new quote).

Python 3.12 released

Posted Oct 3, 2023 16:14 UTC (Tue) by anarcat (subscriber, #66354) [Link]

Well sure, I understand how it works, but if you have to spell it out all the way like this, for me it means we lost something in the translation...

Python 3.12 released

Posted Oct 3, 2023 18:21 UTC (Tue) by Karellen (subscriber, #67644) [Link] (2 responses)

the braces temporarily "cancel" the enclosing quotes

I mean, I guess that's how quotes work in the sh command substitution syntax $(....), but that's shell. It feels... weird and icky to put that sort of thing in a "real" programming language like Python!

Python 3.12 released

Posted Oct 3, 2023 19:13 UTC (Tue) by NYKevin (subscriber, #129325) [Link] (1 responses)

Although PEP 701 does cite bash as inspiration, it also cites several "real" programming languages, including Ruby (🔥 take: Ruby is just Python with different syntax):

> Many languages that allow similar syntactic constructs (normally called “string interpolation”) allow quote reuse and arbitrary nesting. These languages include JavaScript, Ruby, C#, Bash, Swift and many others. The fact that many languages allow quote reuse can be a compelling argument in favour of allowing it in Python. This is because it will make the language more familiar to users coming from other languages.

Python 3.12 released

Posted Oct 3, 2023 22:11 UTC (Tue) by mathstuf (subscriber, #69389) [Link]

I just wish that some of the corner cases didn't exist (Python 3.11):

In [2]: f'a dict: { {1: 2, "a": 4}}'
Out[2]: "a dict: {1: 2, 'a': 4}"

So…`}}` is not an escape for `}`…sometimes?

In [6]: f'a dict: { {1: 2, "a":: 4} }'
Cell In[6], line 1
f'a dict: { {1: 2, "a":: 4} }'
^
SyntaxError: f-string: invalid syntax

I'm not sure why this column marker seems to care so much about the first key when the second key's `::` is the actual problem. Maybe it gets caught as a format specifier somehow?

Python 3.12 released

Posted Oct 3, 2023 18:25 UTC (Tue) by mathstuf (subscriber, #69389) [Link]

That's all well and good, but it seems that syntax highligher libraries will need to learn this. NeoVim 0.9.2 highlights this example as the string ending before that first `,`.

Python 3.12 released

Posted Oct 4, 2023 6:36 UTC (Wed) by epa (subscriber, #39769) [Link]

It would all be more readable with balanced quotation marks “ and ”

It's kind of a historical accident that most programming languages have ended up with the same character to open and close a quoted string.


Copyright © 2023, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds