Given the current semantics of PEP 343 and the following class: class null_context(object): def __context__(self): return self def __enter__(self): return self def __exit__(self, *exc_info): pass Mistakenly writing: with null_context: # Oops, passed the class instead of an instance Would give a less than meaningful error message: TypeError: unbound method __context__() must be called with null_context instance as first argument (got nothing instead) It's the usual metaclass problem with invoking a slot (or slot equivalent) via "obj.__slot__()" rather than via "type(obj).__slot__(obj)" the way the underlying C code does. I think we need to fix the proposed semantics so that they access the slots via the type, rather than directly through the instance. Otherwise the slots for the with statement will behave strangely when compared to the slots for other magic methods. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
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