ManagedProperties strangeness

40 views
Skip to first unread message

Joachim Durchholz

unread,
Mar 10, 2015, 5:46:38 AM3/10/15
to sy...@googlegroups.com
ManagedProperties is declared like this:

class ManagedProperties(with_metaclass(BasicMeta, BasicMeta)):
...

I.e. ManagedProperties has BasicMeta both as its metaclass and as its
superclass (so it is a metaclass itself).

What's the purpose of this construction?
I suspect we should separate the metaclass functionality into a separate
class (or class hierarchy), but it's quite possible that I'm overlooking
something.

(Once I know the purpose, I can analyze how it applies to subclasses
which have a similarly dual superclass-metaclass nature.)

Aaron Meurer

unread,
Mar 10, 2015, 3:31:29 PM3/10/15
to sy...@googlegroups.com
I believe the purpose of this class was to make it easier to remove
the assumptions from the core. I would dig into the pull request and
commits that introduced it to see if there is more information. I
agree it's weird to have BasicMeta be both the metaclass and the
superclass.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/54FEBD76.40302%40durchholz.org.
> For more options, visit https://groups.google.com/d/optout.

Ronan Lamy

unread,
Mar 10, 2015, 7:50:56 PM3/10/15
to sy...@googlegroups.com
Le 10/03/15 09:46, Joachim Durchholz a écrit :
The PR that created this was https://github.com/sympy/sympy/pull/328

There wasn't any discussion about having BasicMeta as a metaclass of
ManagedProperties (called WithAssumptions then), but, IIRC, the reason
was to ensure correct registration of ManagedProperties and its
subclasses. Looking back, I'm not sure that it was really needed.
My suggestion: try removing the metaclass relationship and see if
anything breaks!

Joachim Durchholz

unread,
Mar 11, 2015, 2:12:39 AM3/11/15
to sy...@googlegroups.com
Am 11.03.2015 um 00:51 schrieb Ronan Lamy:
> The PR that created this was https://github.com/sympy/sympy/pull/328

Wow, that's historic :-)

> There wasn't any discussion about having BasicMeta as a metaclass of
> ManagedProperties (called WithAssumptions then), but, IIRC, the reason
> was to ensure correct registration of ManagedProperties and its
> subclasses. Looking back, I'm not sure that it was really needed.

Understandable. Metaclasses can be very confusing the first time you
deal with them.

> My suggestion: try removing the metaclass relationship and see if
> anything breaks!

Good idea, I'll try that.
Right now I'm trying to find out which member functions are part of
Python's metaclass API (I think it's __call__, __new__, and __init__,
but I haven't verified yet). The plan is to use that knowledge split the
metaclass stuff into a different class hierarchy than the non-metaclass
stuff; with luck, most non-meta classes are already there and it doesn't
entail adding many classes.

I have another angle of attack: I suspect that most uses of
with_metaclass are redundant because subclasses inherit the metaclass
anyway.
I hope to reduce the amount of code to worry about when refactoring
metaclasses.
Reply all
Reply to author
Forward
0 new messages