On 2021-10-23, Chris Angelico <ros...@gmail.com> wrote: > I've never used ctr:=ctr-1 either, though, so I don't know the actual > use cases. Why is this being used in an assignment expression? Is it > an ersatz loop? > > Common use-cases include: > > if m := re.match(...): > > while data := thing.read(): > > etc. All of them are doing exactly two things: testing if something is > empty, and if it isn't, using it in a block of code. > > In what situations do you need to mutate an attribute and also test > it, and how much hassle is it to simply break it out into two lines?
It's not hard to imagine something like: def get_expensive(self): return self.expensive or self.expensive := self.calculate_expensive() > The onus is on you to show that it needs to be more flexible. Is it though? It seems to me that the onus is on you to show that this special case is special enough to be given its own unique existence. It's a bit surprising that the PEP doesn't discuss this decision at all. -- https://mail.python.org/mailman/listinfo/python-list