SymTuple did not fulfill foo.func(*foo.args) == foo.  This patch fixes that
by storing the wrapped tuple as .args[0] instead of directly as .args

Updated all SymTuple methods, added a test and fixed some whitespace.
---
 sympy/physics/secondquant.py            |   35 +++++++++++++++++-------------
 sympy/physics/tests/test_secondquant.py |    5 ++-
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/sympy/physics/secondquant.py b/sympy/physics/secondquant.py
index 5d3f77b..4bd9cc2 100644
--- a/sympy/physics/secondquant.py
+++ b/sympy/physics/secondquant.py
@@ -146,32 +146,37 @@ class TensorSymbol(Function):
 
 
 class SymTuple(Basic):
+    """
+    the wrapped tuple is available as self.items
+    """
 
     def __new__(cls, arg_tuple, **kw_args):
-        """
-        the wrapped tuple is available as self.args
-        """
-        obj = Basic.__new__(cls,*arg_tuple, **kw_args)
+        obj = Basic.__new__(cls, tuple(arg_tuple), **kw_args)
         return obj
 
-    def __getitem__(self,i):
-        if isinstance(i,slice):
+    @property
+    def items(self):
+        return self.args[0]
+
+    def __getitem__(self, i):
+        if isinstance(i, slice):
             indices = i.indices(len(self))
-            return SymTuple(tuple([self.args[i] for i in range(*indices)]))
-        return self.args[i]
+            return SymTuple([self.items[i] for i in range(*indices)])
+        return self.items[i]
 
     def __len__(self):
-        return len(self.args)
+        return len(self.items)
 
-    def __contains__(self,item):
-        return item in self.args
+    def __contains__(self, item):
+        return item in self.items
 
-    def _eval_subs(self,old,new):
-        if self==old:
+    def _eval_subs(self, old, new):
+        if self == old:
             return new
-        t=tuple([ el._eval_subs(old,new)  for el in self.args])
-        return self.__class__(t)
+        return self.func([el._eval_subs(old, new) for el in self.items])
 
+    def _sympystr(self, p):
+        return "SymTuple(%s)"%", ".join([p.doprint(i) for i in self.items])
 
 def _tuple_wrapper(method):
     """
diff --git a/sympy/physics/tests/test_secondquant.py 
b/sympy/physics/tests/test_secondquant.py
index f286098..c0d7513 100644
--- a/sympy/physics/tests/test_secondquant.py
+++ b/sympy/physics/tests/test_secondquant.py
@@ -15,13 +15,14 @@
 
 
 def test_SymTuple():
-    t = (1,2,3,4)
+    t = (1, 2, 3, 4)
     st =  SymTuple(t)
     assert set(t) == set(st)
     assert len(t) == len(st)
     assert set(t[:2]) == set(st[:2])
     assert isinstance(st[:], SymTuple)
-    assert st == SymTuple((1,2,3,4))
+    assert st == SymTuple((1, 2, 3, 4))
+    assert st.func(*st.args) == st
     p,q,r,s = symbols('pqrs')
     t2=(p,q,r,s)
     st2 = SymTuple(t2)
-- 
1.6.5

-- 
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patc...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en.

Reply via email to