[Python-ideas] Re: SyntaxError: cannot use assignment expressions with attribute

2023-10-10 Thread Stephen J. Turnbull
Dom Grigonis writes: > Why would this not be a good option? 1 extra line compared to > walrus, but no DRY issue. > with open(“fn") as f: > while True: > line = f.readline() > if line and check(line): > process(line) > else: > break Wo

[Python-ideas] Re: SyntaxError: cannot use assignment expressions with attribute

2023-10-10 Thread Rob Cliffe via Python-ideas
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