Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56563

Re: super in Python 3 and variadic arguments

From Marco Buttu <marco.buttu@gmail.com>
Newsgroups comp.lang.python
Subject Re: super in Python 3 and variadic arguments
Date 2013-10-10 14:54 +0200
Organization Aioe.org NNTP Server
Message-ID <l3681f$gqh$1@speranza.aioe.org> (permalink)
References <l33tlf$rr1$1@speranza.aioe.org> <mailman.902.1381337680.18130.python-list@python.org> <52565598.6000709@gmail.com> <mailman.932.1381403081.18130.python-list@python.org>

Show all headers | View raw


On 10/10/2013 01:04 PM, Ned Batchelder wrote:

> On 10/10/13 3:22 AM, Marco Buttu wrote:
>> >>> import inspect
>> >>> class B(A):
>> ...     def bfoo(*args):
>> ...         frame = inspect.currentframe()
>> ...         for obj, value in frame.f_locals.items():
>> ...             print(obj, value, sep=' --> ')
>> ...         # super().afoo(*args[1:])
>> ...
>> >>> B().bfoo(1, 2, 3)
>> args --> (<__main__.B object at 0x7f28c960a590>, 1, 2, 3)
>> frame --> <frame object at 0x7f28cad4b240>
>>
>> So, why does not super use it?
>>
>
> Python has never claimed the kind of purity that makes everything work
> in a totally simple consistent way.  super() with no args is a kind of
> hack to begin with.  It involves a special case in the compiler (so that
> using the name "super" as a function call will act as if you had
> accessed the name "__class__" so that super can find it later), and
> inspecting the stack frame during execution.

It seems reasonable

> It's an interesting case of the Zen of Python.  It violates one
> ("explicit is better than implicit"), but only because of another one
> ("practicality beats purity").  super(MyClass, self) in Python 2 is the
> kind of brain-bender that so many people get wrong at first, that it's
> helped plenty of people to do the arguments implicitly, even if there
> are oddball edge cases that it doesn't seem to handle properly.
>
> --Ned.

Thanks for the comprehensive answer ;)

-- 
Marco Buttu

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-09 17:44 +0200
  Re: super in Python 3 and variadic arguments Ned Batchelder <ned@nedbatchelder.com> - 2013-10-09 12:47 -0400
    Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-10 09:22 +0200
      Re: super in Python 3 and variadic arguments Ned Batchelder <ned@nedbatchelder.com> - 2013-10-10 07:04 -0400
        Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-10 14:54 +0200
        Re: super in Python 3 and variadic arguments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 02:11 +0000
          Re: super in Python 3 and variadic arguments Ian Kelly <ian.g.kelly@gmail.com> - 2013-10-10 20:33 -0600
            Re: super in Python 3 and variadic arguments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 03:00 +0000
              Re: super in Python 3 and variadic arguments Chris Angelico <rosuav@gmail.com> - 2013-10-11 17:08 +1100
            Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-11 08:17 +0200
          Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-11 08:15 +0200

csiph-web