Live data from Hacker News

What's New in Python 3.12

docs.python.org

81–90 of 120 posts

Re: What's New in Python 3.12

#81

I've been using python for the past 10+ years, and I've got to say that the new Syntactic formalization of f-strings (PEP 701) has got to be one of the most "huh?" changes I've seen in a while. Was this such a big problem? In my experience, the GIL, faster start-up times are so much higher on the totem pole, why this now?

> In my experience, the GIL, faster start-up times are so much higher on the totem pole, why this now?

Are you aware that more than one change can be worked on at a time?

Re: What's New in Python 3.12

#83

I suspect people will use these comments to share their wishlist of Python features, so let me add that I really wish Python had a safe navigation operator, for when you are dealing with nested objects that could be None. I have been trying to parse a lot of XML and JSON in Python lately and a feature like that could really help reduce boilerplate checks. https://en.wikipedia.org/wiki/Safe_navigation_operator

On a library level you could return an "empty" object which you could call methods on, returning empty objects and so on, for chaining.

Re: What's New in Python 3.12

#84
post #70

Earlier quoted context omitted.

Why do you have to keep up with them?

On the principle that it works best when you know your tools. The lament is about the features piling up at such fast pace--and of questionable utility, too--that it's exhausting to keep up/master over. You go for a vaccation, and the language you once knew, mastered, and loved, has left you behind. On the utility of features, the arbitraty nesting of f-strings stands out. Why in tarnation would anyone need such nest…

> Isn't it simpler and readable to keep non-trivial expressions out of the f-string itself?

But then you have to define what non-trivial expressions are, and more importantly, people using the language have to learn that definition too. By having f-strings accept all valid expressions, the language actually becomes simpler.

Re: What's New in Python 3.12

#85

PEP 695 is great. I've been using mypy every day at work in last couple years or so with very strict parameters (no any type etc) and I have experience writing real life programs with Rust, Agda, and some Haskell before, so I'm familiar with strict type systems. I'm sure many will disagree with me but these are my very honest opinions as a professional who uses Python types every day: * Some types are better than no…

> the time raises "KeyError" should actually be typed "Raises[T, KeyError]"

You can't do this in Python your bucket will always have hole you can't plug. Arbitrary exceptions can appear anywhere in your code thanks to signal handlers.

KeyboardInterrupt is the one you probably know without knowing.

Exceptions can even come from higher in the stack down to you with the .throw method on generators.

Re: What's New in Python 3.12

#86

I suspect people will use these comments to share their wishlist of Python features, so let me add that I really wish Python had a safe navigation operator, for when you are dealing with nested objects that could be None. I have been trying to parse a lot of XML and JSON in Python lately and a feature like that could really help reduce boilerplate checks. https://en.wikipedia.org/wiki/Safe_navigation_operator

Python, prouding (← is that a word?笑) itself to be the foremost language of duck typing, I'd really want to see that too.

touting

Re: What's New in Python 3.12

#88
post #70

Earlier quoted context omitted.

Why do you have to keep up with them?

On the principle that it works best when you know your tools. The lament is about the features piling up at such fast pace--and of questionable utility, too--that it's exhausting to keep up/master over. You go for a vaccation, and the language you once knew, mastered, and loved, has left you behind. On the utility of features, the arbitraty nesting of f-strings stands out. Why in tarnation would anyone need such nest…

This sounds like a personal problem, honestly. Do you read every diff too? If not, you can't deeply think through the performance implications of how existing features are changing. What about the rest of your userland? No one expects anyone to do that.

Re: What's New in Python 3.12

#89

Earlier quoted context omitted.

> If a function can realistically raise a "KeyError" the program should be properly written to accept this at some level By definition, it is, because there is defined behavior for unhandled exceptions. If you want to—and this is a valid preference—wrap all exceptions thrown at a lower level and present an API where they are part of the return type that must be addressed by code to pass typechecking, then you do that…

I think that this is a hard problem and you're right that spamming KeyError everywhere is against the exceptionality of exceptions. But the current completely unchecked model is also misleading. I don't have such a great solution in mind but I think mypy should be able to verify each exception type is handled at some point in the stack. I know that it sounds vague, but these are my current unorganized thoughts.

Exceptions are always handled: Python exits while telling you about the exceptional situation.

If you’re saying that I must handle an exception in my code rather than crash because my “fail early, fail often” design choices offend your religious preferences… then keep it to yourself and out of PEPs.

Re: What's New in Python 3.12

#90

I suspect people will use these comments to share their wishlist of Python features, so let me add that I really wish Python had a safe navigation operator, for when you are dealing with nested objects that could be None. I have been trying to parse a lot of XML and JSON in Python lately and a feature like that could really help reduce boilerplate checks. https://en.wikipedia.org/wiki/Safe_navigation_operator

I haven't even used Python for like four years now, but all of these suggestions to do try except and get.key() or {} seem to be ignoring that Python has had a defaultdict in the standard library for, I don't even know, at least the last decade and a half, as long as I've been paying attention. It's even written in C: https://github.com/python/cpython/blob/d9246c7b734b8958da034....
Post reply on HN