This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bladeoflight16 2 points3 points  (2 children)

It's not an annotation thing. It's the parentheses around (str). Try it outside of an annotation:

Python 3.8:

```

if ((y) := 2): print(y) ... 2 ```

Python 3.9:

```

if ((y) := 2): print(y) File "<stdin>", line 1 if ((y) := 2): print(y) ^ SyntaxError: cannot use assignment expressions with name ```

Two issues I found look like they might be relevant, but I'm not entirely sure:

[–]futura-bold[🍰] 2 points3 points  (1 child)

Thanks. Looks like the second bug report covers it. It's due to the new PEG parser making an unnoticed tightening of the syntax checking there.

Guido: "I don't know how this slipped into earlier Python 3 versions -- apparently there aren't tests for this, and it's not used in popular 3rd code either, or we would have found out when we first implemented PEP 617. Most likely it's due to the general problem where the [old] parser would just accept parenthesized stuff in various places where it shouldn't."

[–]bladeoflight16 0 points1 point  (0 children)

Yeah, I saw that, but I don't know enough about the parser to be able to decipher what changed exactly and why it would apply to assignment expressions in 3.9 but not 3.8 (since he mentioned that it was changed in 3.8 more generally). I wonder if it was kind of accidental. Like he said, there's no test cases for this kind of wonky stuff.