Python 3.8.0a1 is now available for testing
pythoninsider.blogspot.com
Python 3.8.0a1 is now available for testing
1–10 of 59 posts
Re: Python 3.8.0a1 is now available for testing
#2I 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... [2] https://mail.python.org/pipermail/python-committers/2018-Jul...
Re: Python 3.8.0a1 is now available for testing
#3 # 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/Re: Python 3.8.0a1 is now available for testing
#4Notably 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 reduc…
Re: Python 3.8.0a1 is now available for testing
#5Notably 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 reduc…
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.
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...
Re: Python 3.8.0a1 is now available for testing
#6Notably 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 reduc…
Re: Python 3.8.0a1 is now available for testing
#7Notably 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 reduc…
Unfortunately "as …" had a few drawbacks in rare use cases (:= has only aesthetic drawbacks), but I think as was by far the most consistent, readable choice and supported ~90% of use cases.
As for the controversy, that's what happens when you reverse 25 year-old design decisions. Shouldn't be too surprising.
Re: Python 3.8.0a1 is now available for testing
#8The 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 par…
Re: Python 3.8.0a1 is now available for testing
#9namedtuple attr access is also now 1.7x faster https://github.com/python/cpython/pull/10495
Other performance improvments : https://github.com/python/cpython/pulls?q=is%3Apr+sort%3Aupd...
Re: Python 3.8.0a1 is now available for testing
#10Notably 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 reduc…