Skip to content
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

Closed
collinwinter mannequin opened this issue May 31, 2006 · 8 comments
Closed

Improve super() objects support for implicit method calls #43439

collinwinter mannequin opened this issue May 31, 2006 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@collinwinter
Copy link
Mannequin

collinwinter mannequin commented May 31, 2006

BPO 1498363
Nosy @birkenfeld, @rhettinger, @terryjreedy
Files
  • better_super.patch: Improve super() objects, against r47124
  • 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:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2010-08-11.19:08:48.712>
    created_at = <Date 2006-05-31.17:31:43.000>
    labels = ['interpreter-core', 'type-feature']
    title = 'Improve super() objects support for implicit method calls'
    updated_at = <Date 2011-02-16.07:32:57.166>
    user = 'https://bugs.python.org/collinwinter'

    bugs.python.org fields:

    activity = <Date 2011-02-16.07:32:57.166>
    actor = 'orsenthil'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2010-08-11.19:08:48.712>
    closer = 'rhettinger'
    components = ['Interpreter Core']
    creation = <Date 2006-05-31.17:31:43.000>
    creator = 'collinwinter'
    dependencies = []
    files = ['7298']
    hgrepos = []
    issue_num = 1498363
    keywords = []
    message_count = 8.0
    messages = ['50385', '50386', '50387', '50388', '50389', '110449', '113455', '113613']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'collinwinter', 'rhettinger', 'terry.reedy', 'BreamoreBoy']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1498363'
    versions = ['Python 3.3']

    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented May 31, 2006

    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.

    @collinwinter collinwinter mannequin self-assigned this May 31, 2006
    @collinwinter collinwinter mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 31, 2006
    @collinwinter collinwinter mannequin self-assigned this May 31, 2006
    @collinwinter collinwinter mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 31, 2006
    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented Jun 27, 2006

    Logged In: YES
    user_id=1344176

    The patch has been updated to reflect the current SVN state,
    r47124.

    @birkenfeld
    Copy link
    Member

    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?

    @collinwinter
    Copy link
    Mannequin Author

    collinwinter mannequin commented Jul 17, 2006

    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.

    @rhettinger
    Copy link
    Contributor

    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).

    @devdanzin devdanzin mannequin added type-feature A feature request or enhancement labels Mar 21, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 16, 2010

    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?

    @terryjreedy
    Copy link
    Member

    I believe this is covered by the PEP-3003 3.2 change moratorium.

    @rhettinger
    Copy link
    Contributor

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants