Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109447
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ben Finney <ben+python@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Subject | Re: Multiple inheritance, super() and changing signature |
| Date | Sat, 04 Jun 2016 10:44:09 +1000 |
| Lines | 56 |
| Message-ID | <mailman.141.1465001065.1839.python-list@python.org> (permalink) |
| References | <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <mailman.54.1464711627.1839.python-list@python.org> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <a17955cb-04d3-9dd6-e2b3-4719269f241d@shopzeus.com> <85k2i65upp.fsf@benfinney.id.au> <b21d46a9-763a-fe38-b539-77867fcdcdc9@shopzeus.com> <85fusu58pw.fsf@benfinney.id.au> <CALwzid=T7QrDpAJYO715iWtkADEhNV=eenAS96j-gMUEMMPTXQ@mail.gmail.com> <85wpm54wbq.fsf@benfinney.id.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de zuAv7ulY01izRC2wIbDfBADjSPXkITNw1fvtxtaDeKMA== |
| Cancel-Lock | sha1:NR/fEVtNW9AnnlePzFCmVIjdiN8= |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; ':-(': 0.07; 'positional': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'semantics': 0.09; 'sucks': 0.09; 'python': 0.10; 'def': 0.13; 'argument': 0.15; '8bit%:26': 0.16; 'argument.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'sign.': 0.16; 'subject:changing': 0.16; 'advocate': 0.22; 'arguments': 0.22; 'code.': 0.23; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'handling': 0.27; 'parameters': 0.27; 'right.': 0.27; 'said,': 0.27; 'function': 0.28; 'actual': 0.28; '**kwargs):': 0.29; 'spam,': 0.29; 'wright': 0.29; 'allows': 0.30; "we're": 0.30; 'class.': 0.30; 'guess': 0.31; 'certain': 0.31; 'another': 0.32; 'skip:_ 10': 0.32; 'though,': 0.32; 'class': 0.33; 'except': 0.34; 'skip:d 20': 0.34; 'running': 0.34; 'next': 0.35; 'unknown': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'method': 0.37; 'received:org': 0.37; 'signature': 0.37; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'matter': 0.63; 'believe': 0.66; '"spam"': 0.84; '_o__)': 0.84; 'cop': 0.84; 'received:125': 0.84; 'inheritance,': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <85wpm54wbq.fsf@benfinney.id.au> |
| X-Mailman-Original-References | <80ea0ea1-5468-2dee-2c38-c2b09801d0f1@shopzeus.com> <mailman.54.1464711627.1839.python-list@python.org> <574e45f4$0$1611$c3e8da3$5496439d@news.astraweb.com> <a17955cb-04d3-9dd6-e2b3-4719269f241d@shopzeus.com> <85k2i65upp.fsf@benfinney.id.au> <b21d46a9-763a-fe38-b539-77867fcdcdc9@shopzeus.com> <85fusu58pw.fsf@benfinney.id.au> <CALwzid=T7QrDpAJYO715iWtkADEhNV=eenAS96j-gMUEMMPTXQ@mail.gmail.com> |
| Xref | csiph.com comp.lang.python:109447 |
Show key headers only | View raw
Ian Kelly <ian.g.kelly@gmail.com> writes:
> Except that since we're discussing design for multiple inheritance,
> the positional argument "spam" is inappropriate. All arguments should
> be passed by keyword; the DolorSitAmet.__init__ method cannot be
> certain that LoremIpsum will be the next class in the MRO, and the
> actual next class might not expect spam to be the first positional
> argument.
You're right. That also allows us to stop handling unknown positional
arguments.
This does make it troublesome to design the function signature though,
and I can see why people balk at how to deal with the semantics of
‘super’ in Python 2::
class LoremIpsum(object):
def __init__(self, **kwargs):
spam = kwargs.pop('spam')
do_something_important_with(spam)
super(LoremIpsum, self).__init__(**kwargs)
class DolorSitAmet(LoremIpsum):
def __init__(self, **kwargs):
self.eggs = kwargs.pop('eggs')
self.beans = kwargs.pop('beans')
super(DolorSitAmet, self).__init__(**kwargs)
That's awful :-( because the initialiser's signature no longer shows any
sign of which parameters matter for this class.
It also sucks to need ‘dict.pop('name')’, instead of just ‘name’.
Keyword-only parameters make this easier and clearer::
class LoremIpsum:
def __init__(self, *, spam, **kwargs):
spam = kwargs.pop('spam')
do_something_important_with(spam)
super().__init__(**kwargs)
class DolorSitAmet(LoremIpsum):
def __init__(self, *, eggs=4, beans=None, **kwargs):
self.eggs = eggs
self.beans = beans
super().__init__(**kwargs)
I guess that's yet another reason to advocate Python 3 for all new code.
--
\ “One time a cop pulled me over for running a stop sign. He |
`\ said, ‘Didn't you see the stop sign?’ I said, ‘Yeah, but I |
_o__) don't believe everything I read.’” —Steven Wright |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-05-31 18:10 +0200
Re: Multiple inheritance, super() and changing signature Steven D'Aprano <steve@pearwood.info> - 2016-06-01 12:18 +1000
Re: Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-03 14:10 +0200
Re: Multiple inheritance, super() and changing signature Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-06-04 13:06 +1200
Re: Multiple inheritance, super() and changing signature Steven D'Aprano <steve@pearwood.info> - 2016-06-04 12:51 +1000
Re: Multiple inheritance, super() and changing signature Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-06-04 23:50 +1200
Re: Multiple inheritance, super() and changing signature Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-03 23:05 -0600
Re: Multiple inheritance, super() and changing signature Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-06-04 23:52 +1200
Re: Multiple inheritance, super() and changing signature Steven D'Aprano <steve@pearwood.info> - 2016-06-04 23:46 +1000
Re: Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-04 16:42 +0200
Re: Multiple inheritance, super() and changing signature Ben Finney <ben+python@benfinney.id.au> - 2016-06-03 22:21 +1000
Re: Multiple inheritance, super() and changing signature Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-06-04 13:10 +1200
Re: Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-03 14:14 +0200
Re: Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-03 14:57 +0200
Re: Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-03 16:06 +0200
Re: Multiple inheritance, super() and changing signature Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-03 08:39 -0600
Re: Multiple inheritance, super() and changing signature Michael Selik <michael.selik@gmail.com> - 2016-06-03 15:33 +0000
Re: Multiple inheritance, super() and changing signature Nagy László Zsolt <gandalf@shopzeus.com> - 2016-06-03 17:59 +0200
Re: Multiple inheritance, super() and changing signature Michael Selik <michael.selik@gmail.com> - 2016-06-03 16:28 +0000
Re: Multiple inheritance, super() and changing signature Ben Finney <ben+python@benfinney.id.au> - 2016-06-04 06:16 +1000
Re: Multiple inheritance, super() and changing signature Ben Finney <ben+python@benfinney.id.au> - 2016-06-04 06:19 +1000
Re: Multiple inheritance, super() and changing signature Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-03 15:53 -0600
Re: Multiple inheritance, super() and changing signature Ben Finney <ben+python@benfinney.id.au> - 2016-06-04 10:44 +1000
csiph-web