
Python 3.8.0a1 is now available for testing - edmorley
https://pythoninsider.blogspot.com/2019/02/python-380a1-is-now-available-for.html
======
luhn
Notably new is the assignment expressions [1]. This was quite controversial
and the battle around it caused Guido to step down as BDFL [2].

I personally think it's quite a nifty feature. I often end up writing
something along the lines of:

    
    
        result = do_something()
        if result:
            do_more(result)
    

Now that can be expressed as:

    
    
        if result := do_something():
            do_more(result)
    

It definitely has the potential to be abused and reduce readability, but
applied well I think it can increase readability.

[1] [https://www.python.org/dev/peps/pep-0572/#relative-
precedenc...](https://www.python.org/dev/peps/pep-0572/#relative-precedence-
of) [2] [https://mail.python.org/pipermail/python-
committers/2018-Jul...](https://mail.python.org/pipermail/python-
committers/2018-July/005664.html)

~~~
muhbags
It is definitely useful, but it severely reduces readability in my opinion.
Your example is also a great example for this. The first version in way more
readable than the second version with the walrus operator.

~~~
gonational
I agree with you.

It's very exciting to remove these sorts of redundant lines, but I cannot
train my brain to intuitively view that line as it will be interpreted.

There is one case where the benefit, IMHO, far outweighs the negatives, and
that can be seen in slides 30-31 of Dustin Ingram's slideshow[1].

PEP 572... the day Python jumped the walrus.

1\. [https://speakerdeck.com/di_codes/pep-572-the-walrus-
operator...](https://speakerdeck.com/di_codes/pep-572-the-walrus-
operator?slide=30)

~~~
legostormtroopr
I can't take a programming talk seriously if it declares in giant font "Less
lines are better" (slide 38).

Any C program can be written as a single line, with no linebreaks - that
doesn't make it "better" by any metric.

Python is built around its readability, and slide 44:

> group = match.group(1) if (match := re.match(data)) else None

is anything but. 'match' is assigned _after_ its first use, and it took me far
to long to mentally parse what it was doing.

~~~
maceurt
C is different than python though. Python already forces readability things
like forcing indent and newline. In most scenarios making a python program in
as few lines as possble will make the program more readible.

------
xtreak29
There were notable performance improvments with several positional argument
only functions made 1.3-1.7x faster in stdlib
[https://bugs.python.org/issue35582](https://bugs.python.org/issue35582).

namedtuple attr access is also now 1.7x faster
[https://github.com/python/cpython/pull/10495](https://github.com/python/cpython/pull/10495)

Other performance improvments :
[https://github.com/python/cpython/pulls?q=is%3Apr+sort%3Aupd...](https://github.com/python/cpython/pulls?q=is%3Apr+sort%3Aupdated-
desc+label%3Atype-performance+is%3Aclosed)

------
nine_k
The key changes seem to be [PEP-572], a bunch of small backward-compatible
syntax changes, a bunch of AST (internal) changes, and bugfixes (of course).

    
    
      # You can now write
      if (match := pattern.search(data)) is not None:
        # Do something with match
      # or even
      [y for x in data if (y := f(x)) is not None]
    

This is what I personally very much anticipated.

Also nice:

    
    
      # This is now supported.
      x: Tuple[int, int] = 1, 2  # No parens.
      yield 1, 2, 3, *rest  # No parens again.
    

[PEP-572]:
[https://www.python.org/dev/peps/pep-0572/](https://www.python.org/dev/peps/pep-0572/)

~~~
mikepurvis
That list comprehension is the most compelling case I've seen for this
functionality; far more so than the basic assignment + if.

~~~
nine_k
Yes, sometimes, writing a comprehension, I was dearly missing the `let` /
`where`, as seen in e.g. Haskell, or lisps.

------
Jeff_Brown
Are assignment expressions the only linguistic change?

For years,I've been holding my breath in Python for sum types, totality
checking, and an enforced, complete type system -- one where you can say "this
should be a list of lists of integers" and it won't let you put any other kind
of thing there.

(Yes, there are external typing solutions like PyPy, but last I checked they
did not offer complete type systems (you could specify that something is a
list, but not that it's a list of ints), nor did they permit totality checking
(so if type X is a sum type with two constructors X1 and X2, and f is a
function that takes an X as input, and you forgot to define what happens if f
is given an X2, it would not know to complain that you hadn't covered all
possibilities).

~~~
netheril96
> but not that it’s a list of ints

Python type annotations do support such use case: List[int].

~~~
Jeff_Brown
Just tried it. What's the point of type signatures if the compiler won't hold
you to the promises you've made? This is in Python 3.6.4:

    
    
      >>> def f (x:int) -> int: return x+1
      ...
      >>> def g (x:str) -> str: return f(x)
      ...
      >>> g(1)
      2
    

I expected a complaint after the second definition: I specified that g takes
and returns a string, and then defined it to take and return an int. Not only
did Python not catch the error at compile time (defining g), it didn't even
catch it at runtime (calling g).

~~~
detaro
Type annotations are just that: annotations. They currently have no meaning to
the CPython interpreter and are purely consumed by external tooling (IDEs,
there's a static typechecker called mypy, ...) or code that chooses to use
them (e.g. there's web frameworks that convert and validate parameter types
according to the signature of the handler function)

------
ian-g
I wonder if anybody has seen anything happening about PEP 582 for a local
packages directory. It's definitely something I'd like to see implemented

------
just_myles
I have done a lot of work in Postgres pgsql writing functions and procedures
and the walrus operator is an assignment operator. Welcome all :D .

~~~
mixmastamyk
It is also assignment in Pascal, though doesn't return the value.

------
mistrial9
I am a proponent of LTS for Python 2.7x and existing libraries. This walrus
operator is a fine new feature, for those that want it in Python 3.8x and
beyond. Sorry, not sorry !

~~~
ma2rten
I can't wait for 2020.

