On Tue, Nov 10, 2015 at 2:21 AM, Francesco Bonazzi <[email protected]> wrote: > > > On Tuesday, 10 November 2015 00:04:39 UTC+1, Aaron Meurer wrote: >> >> I'm trying to fix sympy.vector.Point so that it follows the args >> invariant. Right now, there is a check that the parent_point must be a >> Point instance, but it can also be None, in which case, it is set to a >> Symbol. This causes a Point constructed in such way to not follow >> expr.func(*expr.args) == expr. > > > There are also some subclassing of Symbol and ignoring the parameter > extensions: > https://github.com/sympy/sympy/blob/01b4f8d97be55746ee2abe38163b533ca5318ba7/sympy/vector/scalar.py#L14 > > index and system are defining parameters, they should be in the .args. > > Perhaps one should follow the example in sympy.diffgeom, > https://github.com/sympy/sympy/blob/f3de4f3698c28355d6397e917b3d9d5bbf9c84c0/sympy/diffgeom/diffgeom.py#L467 > > BaseScalarField in diffgeom is the analogous of BaseField in vector. > >> >> Example: >> >> In [11]: from sympy.vector import * >> >> In [12]: C = CoordSysCartesian('C') >> > > If I remember correctly, the letter 'C' (the name of the coordinate system) > doesn't get registered in the args, that's another issue.
Yes, I already fixed that at https://github.com/sympy/sympy/pull/10084 (see https://github.com/asmeurer/sympy/commit/4fc85947aeccd78907f320ede0f93f444eb68609). This is because subclasses of Symbol have some problems with caching that are leading to test failures in Python 3.5, but regardless, an object with arguments shouldn't subclass Symbol (it turns out that due to the way caching works right now, really nothing should subclass Symbol if it intends to extend it in any way, but even without this issue, any subclass of Symbol should have empty .args). > >> >> >> As a side note, the fact that this sort of thing exists in SymPy is >> embarrassingly bad. We should fix test_args to test that objects are >> recreatable from their arguments and put a moratorium on new objects >> that don't follow that rule. >> > > It's a bit complicated to explain to new users how to write class > constructors. > > Mathematica has a pattern matching syntax that forces you to keep its > equivalent of SymPy's args sorted in this particular way. We could enforce the "args must be instances of Basic" in the Basic metaclass. That would be a bit extreme, though, and it would at least require fixing the existing classes in SymPy first. The second rule can be enforced for library code in tests. I've started this at https://github.com/sympy/sympy/pull/10128. I doubt I will finish it before the release, unless someone else wants to help out. Beyond that, we desperately need documentation on how to properly subclass SymPy objects and how to create your own objects in general. I opened https://github.com/sympy/sympy/issues/10132. 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 [email protected]. > To post to this group, send email to [email protected]. > 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/90c852e2-911c-4be1-93b0-6798e7736d5e%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 [email protected]. To post to this group, send email to [email protected]. 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/CAKgW%3D6KinDxEyoVAd5BruVeB9ackMA3etxrmdm0zYh__g3izZQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
