Patches item #1498363, was opened at 2006-05-31 12:31 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1498363&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core (C code) Group: Python 2.6 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Collin Winter (collinwinter) >Assigned to: Collin Winter (collinwinter) Summary: Improve super() objects support for implicit method calls Initial Comment: The attached patch lets super() objects pass on implicit __getitem__, __setitem__, __delitem__, __len__ and __hash__ calls. For example, to use len() with super() objects, one must currently do something like super(X, X()).__len__() Likewise for __getitem__, super(X, X()).__getitem__(item) That's ugly. This patch lets these be spelled as len(super(X, X())) and super(X, X())[item], respectively. The patch also includes documentation updates and tests for the new functionality. The patch was taken against r46582. ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2007-04-02 21:33 Message: Logged In: YES user_id=80475 Originator: NO At one time, I had explored adding some of these methods and then dropped the idea because it left super() with an odd mish-mash of methods that are 1) forwarded 2) not-supported 3) handled directly by the super-object itself. For instance, the repr() of a super-object and is handled directly by the super object. Likewise, the members are part of the super-object and not forwarded. The current state of affairs can be explained (approximately) with the notion that named methods are forwarded but not any of the syntax-assisted implicit calls. This patch clutters that state-of-affairs for a questionable benefit. If you want to push for this, it should be discussed on python-dev so we can reach a concensus on what super-objects should be expected to do and not do. Is it clear that so.__self__ and repr(so) act on the super object while a call like so[x] will traverse the mro? Also, if something like this does go in, please optimize the calls to PyString_FromString() to be invoked no more than once per Python session (otherwise, syntax driven implicit calls may end-up being slower than named method access). ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2006-07-17 08:13 Message: Logged In: YES user_id=1344176 I only added these particular methods because they were a) the only ones I needed at the time, b) the only ones I really had time to implement. I've now got a few more tuits freed up, so I'd be happy to implement more of these methods. As for "explicit is better than implicit", I don't see how that applies here. The same case could be made for all of Python's syntax-assisted method calls. ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2006-07-17 08:05 Message: Logged In: YES user_id=849994 Why only these methods? Why not __add__, __call__ etc.? Implementing all of these methods is a pain and adds considerable complexity to typeobject.c. Frankly, I don't see an improvement since you normally only call super.__getitem__ in __getitem__, and explicit is better than implicit. Raymond, do you have a second opinion? ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2006-06-27 07:22 Message: Logged In: YES user_id=1344176 The patch has been updated to reflect the current SVN state, r47124. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1498363&group_id=5470 _______________________________________________ Patches mailing list [email protected] http://mail.python.org/mailman/listinfo/patches
