1. 12

  2. 15

    I was kind of hoping this wouldn’t get accepted. IMHO this seems to reduce readability.

    I read somewhere the “as” syntax being mentioned for if/while constructs, which I personally find much more readable.

    So, instead of,

    if (match := pattern.search(data)) is not None:

    something like,

    if pattern.search(data) as match is not None:

    Although I guess as with everything, we’ll get used to it. 🤷‍♂️

    1. 4

      EXPR as NAME syntax is mentioned in the proposal itself under “Alternative spellings” section. Unfortunately, except EXPR as NAME syntax already exists in Python, and this syntax scopes NAME inside except clause unlike this proposal, so there is grammar conflict.

      1. 2

        I agree that readability seems to suffer here. I have certainly written code that looked like the examples but they never resulted in performance costs high enough to justify an alternative syntax. I’m curious to see where the named expressions get taken up.

      2. 3

        This proposal has been up for a while, but what changed is that the proposal will be accepted.

        1. 1

          While it reduces readability, I’ve definitely had cases where having assignment expressions would have meant one less function call. Used sparingly, I think it’s a useful tool to have.

          1. 1

            lol in 2.7 one can already do this with list comphrensions:

            [GCC 6.3.0 20170516] on linux2
            Type "help", "copyright", "credits" or "license" for more information.
            >>> a
            Traceback (most recent call last):
              File "<stdin>", line 1, in <module>
            NameError: name 'a' is not defined
            >>> [None for a in [1]]
            >>> a
            >>> 1 + 2 - ([None for a in [2]], 2)[1]
            >>> a
            1. 1

              I might have missed an important point here, but couldn’t a more lightweight lambda / block syntax (not scoped) achieve approximately the same thing?

              Something like:

              z = {y=2}

              Where { is for a block of code.

              Instead of:

              z = (y := 2)

              Or are there fundamental differences?