The fact that it is not allowed is nothing to do with the 'return'. You
*can* write
return (x := x+1)
What you can't (at present) do is use the walrus operator with an attribute:
x = (self.a := self.a + 1) # SyntaxError
I too have found times when this would be convenient.
As Stephen says, Python often adds new features conservatively, then
extends them later if/when it seems desirable. This happened with the
'@' decorater: originally it came with all manner of restrictions, but
eventually they were removed. IMO this was a good thing because it made
the language more uniform, meaning you didn't have to remember what was
allowed and what wasn't; so I hope the same will happen with the walrus
operator.
Best wishes
Rob Cliffe
On 09/10/2023 02:17, Dom Grigonis wrote:
Is there a reason why this is not allowed?
return (self.mode := self.mode_valid(mode))
_______________________________________________
Python-ideas mailing list --python-ideas@python.org
To unsubscribe send an email topython-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived
athttps://mail.python.org/archives/list/python-ideas@python.org/message/EULXNH2OQOY72LDAMQSRLA3JKU55UBG6/
Code of Conduct:http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/TUZFTPSM3VSFGDCJLJKX2C5MSPMMCVV7/
Code of Conduct: http://python.org/psf/codeofconduct/