What is the semantics meaning of 'object'?
Ethan Furman
ethan at stoneleaf.us
Wed Jun 26 16:37:37 EDT 2013
On 06/23/2013 12:05 PM, Ian Kelly wrote:
> On Sun, Jun 23, 2013 at 12:46 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> All is not lost, there are ways to make your classes cooperative. The
>> trick is to have your classes' __init__ methods ignore keyword arguments
>> they don't know what to do with. object used to do the same thing, but it
>> no longer does, so you need to add an extra class just before object to
>> swallow any args before they read object.
>>
>>
>> class Blocker(object):
>> def __init__(self, **kwargs):
>> # Block kwargs from reaching object
>> super(Blocker, self).__init__()
>
> I don't like the idea of doing this with a cooperative __init__
> method. If any keyword arguments were passed that weren't consumed,
> that is probably a bug, and this just swallows the exception instead
> of reporting it.
+1
Z
> Of course, if you're doing cooperative inheritance with some other
> method that doesn't exist on object, then this technique is necessary
> to prevent the topmost class from trying to call that method on object
> and erroring out.
But in that case the Blocker wouldn't call super since it is acting as the base class.
--
~Ethan~
More information about the Python-list
mailing list