On Tue, Apr 6, 2021 at 12:40 PM Terry Reedy <tjre...@udel.edu> wrote: > > On 4/5/2021 3:32 PM, Chris Angelico wrote: > > > On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy <tjre...@udel.edu> wrote: > >> Python *could* do the same for expresssions: load 'a' (in this case) > >> once into a register or stack slot and use that value consistently > >> throughout the expression. Replacing the eval with the following exec > >> has the same effect. > > > > True, but I think that this would be enough of a semantic change that > > Python should be very VERY careful about doing it. > > I consider it beyond a possibility. >
I just realised that the whole eval/exec/namespace stuff is massive overkill. All you need is an object that is inconsistent in its boolification... >>> class Wat: ... def __bool__(self): ... self.state = not getattr(self, "state", False) ... return self.state ... >>> a = Wat() >>> a and not a True ChrisA -- https://mail.python.org/mailman/listinfo/python-list