SymTuple did not fulfill foo.func(*foo.args) == foo.  This patch fixes that
by treating the constructor *args as items of the tuple, rather than expecting
exactly one tuple argument.

Added docstring, doctest and test  +  fixed some related whitespace errors.
---
 sympy/physics/secondquant.py            |   31 +++++++++++++++++--------------
 sympy/physics/tests/test_secondquant.py |    9 +++++----
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/sympy/physics/secondquant.py b/sympy/physics/secondquant.py
index 5d3f77b..269df9a 100644
--- a/sympy/physics/secondquant.py
+++ b/sympy/physics/secondquant.py
@@ -146,18 +146,27 @@ class TensorSymbol(Function):
 
 
 class SymTuple(Basic):
+    """
+    Wrapper around the builtin tuple object
 
-    def __new__(cls, arg_tuple, **kw_args):
-        """
-        the wrapped tuple is available as self.args
-        """
-        obj = Basic.__new__(cls,*arg_tuple, **kw_args)
-        return obj
+    The SymTuple is a subclass of Basic, so that it works well in the
+    Sympy framework.  The wrapped tuple is available as self.args, but
+    you can also access elements or slices with [:] syntax.
+
+    >>> from sympy import symbols
+    >>> from sympy.physics.secondquant import SymTuple
+    >>> a, b, c, d = symbols('a b c d')
+    >>> SymTuple(a, b, c)[1:]
+    SymTuple(b, c)
+    >>> SymTuple(a, b, c).subs(a, d)
+    SymTuple(d, b, c)
+
+    """
 
     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 SymTuple(*[self.args[i] for i in range(*indices)])
         return self.args[i]
 
     def __len__(self):
@@ -166,12 +175,6 @@ def __len__(self):
     def __contains__(self,item):
         return item in self.args
 
-    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)
-
 
 def _tuple_wrapper(method):
     """
@@ -181,7 +184,7 @@ def wrap_tuples(*args, **kw_args):
         newargs=[]
         for arg in args:
             if type(arg) is tuple:
-                newargs.append(SymTuple(arg))
+                newargs.append(SymTuple(*arg))
             else:
                 newargs.append(arg)
         return method(*newargs, **kw_args)
diff --git a/sympy/physics/tests/test_secondquant.py 
b/sympy/physics/tests/test_secondquant.py
index f286098..61b2276 100644
--- a/sympy/physics/tests/test_secondquant.py
+++ b/sympy/physics/tests/test_secondquant.py
@@ -15,16 +15,17 @@
 
 
 def test_SymTuple():
-    t = (1,2,3,4)
-    st =  SymTuple(t)
+    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)
+    st2 = SymTuple(*t2)
     assert st2.atoms() == set(t2)
 
 def test_PermutationOperator():
-- 
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