0

Is there any technical reason not to enable assignment expressions as default behavior of the language? I mean for assignment operations to always return their value, like:

a = (b = 1)

Please note I am not looking for opinions. I am looking for technical reasons (backward incompatibilities for instance) that prevent such implementation. This seems like genuinly useful feature, like if in Scala.

Marcin
  • 4,080
  • 1
  • 27
  • 54
  • 1
    your code does not represent an assignment expression in the sense of the PEP... `a = b = 1` works fine already... – hiro protagonist Oct 21 '19 at 13:09
  • 2
    Assignment *isn't* an expression at all; it's a statement. This was a deliberate choice to prevent `if b = 1:` from parsing at all, so that you can't write that instead of `if b == 1:` by mistake. – chepner Oct 21 '19 at 13:09
  • @hiroprotagonist, with parentheses it does not. – Marcin Oct 21 '19 at 13:10
  • @Marcin i know (that is the reason i left them out...). but you are right, that is not really an answer to your question (hence just a comment). – hiro protagonist Oct 21 '19 at 13:11
  • In Py 3.8 `a = (b := 1)` works just fine, so it appears to be "enabled" by default — so your premise is wrong. – martineau Oct 21 '19 at 13:14

0 Answers0