__init__ keyword param for sub-class?
Grant Edwards
grant at nowhere.
Thu Dec 23 14:44:44 EST 1999
Fred L. Drake, Jr. wrote:
> > I want to sub-class something that takes one positional and a
> > whole slew of keyword arguements when the object is
> > instantiated, and I want to add one keyword argument (keyword
> > 'myoption' in the below example) to be handled by my method,
> > and pass the rest on the the super-class. I couldn't find any
>
> That's what I've always done. There is at least one proposal to
>extend the call syntax to make the apply() unnecessary, but it's not
>in the core (though I seem to recall a patch to actually implement
>it).
> return Pmw.ScrolledText.__init__(self, *posArgs, **keyArgs)
Yea, I remember this being discussed. It's certainly easier to
read this way.
> I think it would be nice to have a way to specify that an argument
>*must* be given as a keyword parameter, and have it never be filled in
>from positional parameters. Perhaps something lispish:
>
> def __init__(self, *posArgs, **keyArgs, :myoption):
> self.__myoption = myoption
> return Pmw.ScrolledText.__init__(self, *posArgs, **keyArgs)
That would be cool too. Certainly easer to read.
In my example I deleted the keyword option after begin grokked
by my method, even though the Pmw __init__() didn't complain
when I left it there.
In Python is it considered good practice for methods/functions
to complain about unrecognized keyword options, or are they
generally just ignored?
One thing I miss from having used Smalltalk is some general way
to refer to the superclass. Having a method specify the
superclass explicitly hampers reuse (at least in theory), and
seems a bit more fragile. I've read that picky a superclass
method would get sticky in a multiple inheritence system, but
the same issue comes up with overlapping superclass methods
that the subclass doesn't override. Right? So, I don't know
why we couldn't use the same mechanism to pick
Super.methodName() that would be used to do self.methodName()
when methodName isn't overridden.
Did that make sense?
--
Grant Edwards grante Yow! O.K.! Speak with a
at PHILADELPHIA ACCENT!! Send
visi.com out for CHINESE FOOD!! Hop
a JET!
More information about the Python-list
mailing list