Live data from Hacker News

What's Coming in Python 3.8

lwn.net

91–100 of 558 posts

Re: What's Coming in Python 3.8

#91
post #5

Walrus operator looks like a great addition, not too much syntax sugar for a common pattern. Why were folks arguing about it?

I don't know how you read it - 'if x is assigned the value y'? Most other things in Python can just be read out loud.

You could read "if x := y()" as "if x gets a truthy value from y()."

For what it's worth, "x = y()" is one of the harder things for new programmers to translate to English in the first place -- it reads most naturally as "x equals y," but leads to better intuitions as "x gets the value of y". I think that's what makes this clunky to verbalize, rather than the "if truthy" bit.

Re: What's Coming in Python 3.8

#92

The lack of the "nursery" concept for asyncio really sucks. Originally I heard it was coming in 3.8. Right now asyncio has this horrible flaw where it's super easy to have errors within tasks pass silently. It's a pretty large foot gun.

You can code your own wrapper for this.

Like https://github.com/Tygs/ayo

It's not as good as having it in the stdlib, because people can still call ensure_future and not await it, but it's a huge improvement and completly compatible with any asyncio code.

Re: What's Coming in Python 3.8

#93
post #8

Python looks more and more foreign with each release. I'm not sure what happened after 3.3 but it seems like the whole philosophy of "pythonic", emphasizing simplicity, readability and "only one straightforward way to do it" is rapidly disappearing.

I'm working on a language with a focus on simplicity and "only one way to do it": https://vlang.io

The development has been going quite well:

https://github.com/vlang/v/blob/master/CHANGELOG.md

Re: What's Coming in Python 3.8

#94
post #24
post #8

Python looks more and more foreign with each release. I'm not sure what happened after 3.3 but it seems like the whole philosophy of "pythonic", emphasizing simplicity, readability and "only one straightforward way to do it" is rapidly disappearing.

“I've come up with a set of rules that describe our reactions to technologies: 1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works. 2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. 3. Anything invented after you're thirty-five is against the n…

I don't think it's just >35-year-olds who find what's going on in Python against the natural order of things?

Re: What's Coming in Python 3.8

#95
post #30

Earlier quoted context omitted.

> It's not clear to me what it does just from reading it How isn't it entirely obvious? := is the assignment operator in tons of languages, and there's no reason not to have assignment be an expression (as is also the case in many languages).

It looks to me like it could be an assignment to const, or, a copy vs a non-copy - it’s not obvious at all. I’m sure: ‘?=‘ was fought over and rejected, but that’s what I’d have expected conditional assignment to look like.

It is not "conditional assignment" tho. It is an assignment which returns the assigned value. You can use it in conditions, but you can also use it elsewhere.

Re: What's Coming in Python 3.8

#96
The title made me think "Be afraid. Be very afraid". But it's all little stuff.

Unchecked type annotations remain the worst addition since 3.0. Actual typing might be useful; it allows optimizations and checking. But something that's mostly a comment isn't that helpful.

Re: What's Coming in Python 3.8

#97
post #62

Earlier quoted context omitted.

But now there are two ways to do assignment. That's not very pythonic, is it?

Regular = can only be used in statements. Walrus := can only be used in expressions. There's no overlap there. However, := does simplify certain expressions (like those nested if-else statements and the common "while chunk := read()" loop), which I think does justify its existence.

This honestly makes it seem more confusing to me. The fact that there is now an operator that can only be used in certain statements just makes things more confusing. And if there really is no overlap, then why wasn't the "=" operator just extended to also work in expressions? "while chunk = read()" seems like it makes just as much sense without adding the confusion of another operator.

Re: What's Coming in Python 3.8

#98

The changes to f-strings just seems like a step in the wrong direction. Don't make the string content implicit!

Also, why abandon printf-style? All languages tend to converge to printf over time, it's simply the most tried and tested model out there!

https://pyformat.info/

Re: What's Coming in Python 3.8

#99

I dont like the positional only arguments.. Really, I dont like anything that trys to force a future developer into using your code the way you expect them to.

I think the main value is that function documentation becomes slightly less absurd.

If you run `help(pow)` as early as Python 3.5 it lists the signature as `pow(x, y, z=None, /)`. The first time I saw that `/` I was pretty confused, and it didn't help that trying to define a function that way gave a syntax error. It was this weird thing that only C functions could have. It's still not obvious what it does, but at least the signature parses, which is a small win.

Another thing it's good for is certain nasty patterns with keyword arguments.

Take `dict.update`. You can give it a mapping as its first argument, or you can give it keyword arguments to update string keys, or you can do both.

If you wanted to reimplement it, you might naively write:

  def update(self, mapping=None, **kwargs):
      ...
But this is wrong. If you run `d.update(mapping=3)` you won't update the 'mapping' key, you'll try to use `3` as the mapping.

If you want to write it in pure Python

  def update(*args, **kwargs):
      if len(args) > 2:
          raise TypeError
      self = args[0]
      mapping = None
      if len(args) == 2:
          mapping = args[1]
      ...
That's awful.

Arguably you shouldn't be using keyword arguments like this in the first place. But they're already used like this in the core language, so it's too late for that. Might as well let people write this:

  def update(self, mapping=None, **kwargs, /):
      ...

Re: What's Coming in Python 3.8

#100
post #8

Python looks more and more foreign with each release. I'm not sure what happened after 3.3 but it seems like the whole philosophy of "pythonic", emphasizing simplicity, readability and "only one straightforward way to do it" is rapidly disappearing.

Can you give an example of something like this happening to the language? IMO 3.6+ brought many positive additions to the language, which I also think are needed as its audience grows and its use cases expand accordingly.

The walrus operator makes while loops easier to read, write and reason about.

Type annotations were a necessary and IMO delightful addition to the language as people started writing bigger production code bases in Python.

Data classes solve a lot of problems, although with the existence of the attrs library I'm not sure we needed them in the standard library as well.

Async maybe was poorly designed, but I certainly wouldn't complain about its existence in the language.

F strings are %-based interpolation done right, and the sooner the latter are relegated to "backward compatibility only" status the better. They are also more visually consistent with format strings.

Positional-only arguments have always been in the language; now users can actually use this feature without writing C code.

All of the stuff feels very Pythonic to me. Maybe I would have preferred "do/while" instead of the walrus but I'm not going to obsess over one operator.

So what else is there to complain about? Dictionary comprehension? I don't see added complexity here, I see a few specific tools that make the language more expressive, and that you are free to ignore in your own projects if they aren't to your taste.

Post reply on HN