[Python-ideas] A (meta)class algebra
Paul Moore
p.f.moore at gmail.com
Thu Feb 12 11:19:47 CET 2015
On 12 February 2015 at 10:09, Martin Teichmann <lkb.teichmann at gmail.com> wrote:
> def CalculateMetaclass(metatype, type):
> winner = metatype
> for b in type.__bases__:
> if issubclass(winner, b):
> continue
> elif issubclass(b, winner):
> winner = b
> continue
> else:
> raise TypeError("metaclass conflict")
> return winner
>
> I would replace that with the following function, which uses addition
> istead of issubclass:
>
> def CalculateMetaclass(metatype, type):
> winner = metatype
> for b in type.__bases__:
> try:
> winner = winner + b
> except TypeError:
> raise TypeError("metaclass conflict")
That doesn't seem like a major improvement. You saved a couple if
lines of pretty readable code, for use of a + operator that doesn't
really add things, but rather returns one or the other of its
operands.
And of course, unless you are writing exclusively for Python 3.5
(3.6?) or later, you'd need the original version for backward
compatibility anyway.
Paul
More information about the Python-ideas
mailing list