Live data from Hacker News

What's New in Python 3.12

docs.python.org

41–50 of 120 posts

Re: What's New in Python 3.12

#41

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?

As a data scientist using dataframes, I'll often do print(f"Total for X is {df["col"].sum()}"). It's annoying to have to remember to switch the type of quotation mark to avoid a crash.

I suspect, a lot of people that spend time in jupyter notebooks are in the same boat. You could argue I should be setting a variable but these are experimental scripts and it's annoying. I welcome it!

Re: What's New in Python 3.12

#42

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

You can participate in the latest iteration of discussing this feature here: https://discuss.python.org/t/introducing-a-safe-navigation-o...

Re: What's New in Python 3.12

#43

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

While not as short as a proper operator .get("key", {}) does work.

Of course this only works at one level and not arbitrarily deeply, but you still need to check for None with this code; it may actually be better to write `x.get("key") or {}` so that you always get an empty dict.

I write 'may' because the difference between None and an empty dict may be very subtle and rarely does the API specify with enough precision what are supposed to be the semantics of each case.

Re: What's New in Python 3.12

#44

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.

Re: What's New in Python 3.12

#45

Is there a reason this is on the frontpage, were there updates? Because 3.12 is out since two weeks. Am I missing something?

Not sure but Python 3.12 was indeed discussed here on HN a couple weeks ago with 600+ upvotes and 300+ comments:

https://news.ycombinator.com/item?id=37737519

Re: What's New in Python 3.12

#46

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

The syntax has a bit of a learning curve, but there's a library called glom that can be helpful in parsing heterogeneous JSON. Specifically it has a coalesce operator that let's you define multiple paths to get the data you are trying to get at, with a default value if none of the paths are valid.

https://glom.readthedocs.io/en/latest/api.html#defaults-with...

e.g.

    target = [{"a": {"b": "c"}}, {"a": {"c": "e"}}, {"a": {}}]
    results = glom(target, [Coalesce("a.b", "a.c", default="")]) # -> ["c", "e", ""]

Re: What's New in Python 3.12

#47

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.

'priding' is idiomatic English

Re: What's New in Python 3.12

#48

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…

Are there any other languages where typing is purely optional and yet so much effort is going into developing the typing system? I started experimenting with Kotlin just when Python was starting to get type hints and after my experience with Kotlin I am totally sold on the benefits of typing. So to me it's great to see these recent developments. It just feels weird to me to have a language that is fundamentally dynam…

[deleted]

Re: What's New in Python 3.12

#49

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.

Priding ;)
Post reply on HN