New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve super() objects support for implicit method calls #43439
Comments
The attached patch lets super() objects pass on 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 The patch was taken against r46582. |
Logged In: YES The patch has been updated to reflect the current SVN state, |
Logged In: YES Why only these methods? Why not __add__, __call__ etc.? Frankly, I don't see an improvement since you normally only |
Logged In: YES I only added these particular methods because they were a) As for "explicit is better than implicit", I don't see how |
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). |
msg50389 asked for this to be discussed on python-dev. I've searched the archives but didn't find anything obvious. Did I simply miss it or was it never discussed? |
I believe this is covered by the PEP-3003 3.2 change moratorium. |
Am rejecting this feature request because of the concerns mentioned in the post on 4/3. The current requirement for explicit forwarding may be slightly inconvenient to type but it does add provide clarity that the method should be applied to the next-in-mro instead of the super object itself. I appreciate the idea but think it would complicate an object that is already very difficult to understand and use correctly. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: