On Fri, Jun 14, 2013 at 12:13 PM, Matthew Rocklin <[email protected]> wrote:
> My understanding of the Python object model was that all attributes are
> stored in the __dict__ attribute.  One can avoid creating __dict__ by
> specifying __slots__, a fixed list of strings of names of attributes.
>
> SymPy only sort of follows this - I'm confused and am looking for
> explanation
>
> In [1]: Basic.__slots__
> Out[1]: ['_mhash', '_args', '_assumptions']
>
> In [2]: Mul.__slots__
> Out[2]: []

__slots__ is only there for performance and memory purposes. Since
Basic objects are immutable, it really doesn't matter that it is there
from a user perspective, since they should be mutating the object
anyway. Also, you'll note that these are all internal things. _args is
not the same as args. _assumptions is not the same as assumptions0.

>
> Questions:
>
> 1.  Doesn't this claim that Mul has no attributes?

It claims that it has no additional attributes, aside from those
defined in the class or inherited from superclasses.

In [14]: (x*y).a = 1
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-242a75c3da7c> in <module>()
----> 1 (x*y).a = 1

AttributeError: 'Mul' object has no attribute 'a'

> 2.  Should _assumptions be on Basic or on Symbol?

I think Basic, since non-Symbol objects have assumptions.

> 3.  Is there any fundamental way to determine all identifying information of
> a Python class?

Not that I know of. You could take a look at how deepcopy works, but
even that doesn't always get everything. The problem is that classes
have a lot of information: methods/attributes, type (metaclass), super
classes, the module (or more generally, namespace) it lives in, its
name, its namespace, and almost all of these things can be defined
dynamically.

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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to