metaclass & __slots__

Alex Martelli aleax at aleax.it
Fri Jul 5 11:07:19 EDT 2002


Jonathan Hogg wrote:
        ...
> Unfortunately, you can't set or modify __slots__ in the __init__ method of
> a metaclass. The damage has already been done by the time you get to the
> __init__ method:
        ...
> You need to make the change in the __new__ method before the class is

Perfectly right!  I should have checked whether __slots__ was taken into
consideration in type's __new__ or __init__, but I was lazy or hurried and
just focused on the obvious issue that the original poster's code called
type.__init__ at the start of the custom metaclass's own __init__, so it
wouldn't have worked "even if" it was type.__init__'s job, rather than
type.__new__'s, to implement __slots__.  Thanks for the correction!


Alex




More information about the Python-list mailing list