[Python-ideas] Abstract metaclasses?
Ethan Furman
ethan at stoneleaf.us
Thu Sep 11 00:29:07 CEST 2014
On 09/10/2014 03:15 PM, Erik Bray wrote:
> On Wed, Sep 10, 2014 at 5:41 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> On 09/10/2014 01:59 PM, Erik Bray wrote:
>>>
>>>
>>> --> import abc
>>> --> class Meta(type, metaclass=abc.ABCMeta):
>>> ... @abc.abstractmethod
>>> ... def foo(cls): pass
>>> ...
>>> --> class A(metaclass=Meta): pass
>>> ...
>>> --> A
>>> <class '__main__.A'>
>>
>>
>> I think this is a bug. However, if the class were:
>>
>> --> class A(metaclass=Meta):
>> ... def foo(self):
>> ... pass
>> ...
>>
>> Then this should succeed, and I don't think your Abstractable type allows
>> it.
>
> I don't necessarily agree that that should succeed. The use of an
> abstract meta-class is basically requiring there to be a concrete
> *classmethod* of the name "foo", (an unbound instancemethod wouldn't
> suffice).
If that is what you want you should use `abstractclassmethod`.
> What maybe *should* work, but doesn't with this implementation is:
>
> class A(metaclass=Meta):
> @classmethod
> def foo(cls):
> pass
Well, take out the 'maybe' and I'm in agreement. ;)
> Alternatively it could just be required that an abstract metaclass
> simply can't be used as a metaclass unless a concrete subclass is
> made.
-1
> But using @classmethod to override abstract class methods does
> make some intuitive sense.
+1
--
~Ethan~
More information about the Python-ideas
mailing list