On 3/18/2014 3:52 AM, Maciej Fijalkowski wrote: > Hi > > I have a question about calling __eq__ in some cases. > > We're thinking about doing an optimization where say: > > if x in d: > return d[x] if d.__contains__(x): return d.__getitem__(x) I do not see any requirement to call x.__eq__ any particular number of times. The implementation of d might always call somekey.__eq__(x). The concept of sets (and dicts) requires coherent equality comparisons. > where d is a dict would result in only one dict lookup (the second one > being constant folded away). The question is whether it's ok to do it, > despite the fact that it changes the semantics on how many times > __eq__ is called on x. A __eq__ that has side-effects violates the intended and expected semanitics of __eq__. -- Terry Jan Reedy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4