A.M. Kuchling schrieb: > What about turning all references to obj.items into the equivalent > bytecode for this: > > if isinstance(obj, dict): # XXX should this be 'type(obj) is dict'? > if <2.x behaviour>: _temp = obj.items > elif <3.x behaviour>: _temp = obj.iteritems > else: > _temp = obj.items > > Ugly; very ugly. This would "work", I think, although I'd rather add a tp_getattr3 slot to types, as somebody else proposed: getattr3 would default to getattr if not defined, and would look up iteritems when asked for iter on dict objects. It would still "suffer" from the cross-module issue: # a.py from __future__ import items_is_iterator def f(d): return d.items # b.py import a d = d{} print a.f(d)() For compatibility with 2.x, a.f should really return a bound method that returns lists; for compatibility with 3.x, it will return a method that produces an iterator. Of course, one might say "don't do that, then". Regards, Martin
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