Expression.symbol moved to Symbol.name
authorVivien Maisonneuve <v.maisonneuve@gmail.com>
Thu, 19 Jun 2014 09:42:59 +0000 (11:42 +0200)
committerVivien Maisonneuve <v.maisonneuve@gmail.com>
Thu, 19 Jun 2014 15:42:13 +0000 (17:42 +0200)
pypol/linear.py
tests/test_linear.py

index 3cd7633..621a157 100644 (file)
@@ -69,7 +69,7 @@ class Expression:
         self._coefficients = {}
         for symbol, coefficient in coefficients:
             if isinstance(symbol, Symbol):
         self._coefficients = {}
         for symbol, coefficient in coefficients:
             if isinstance(symbol, Symbol):
-                symbol = str(symbol)
+                symbol = symbol.name
             elif not isinstance(symbol, str):
                 raise TypeError('symbols must be strings or Symbol instances')
             if isinstance(coefficient, Constant):
             elif not isinstance(symbol, str):
                 raise TypeError('symbols must be strings or Symbol instances')
             if isinstance(coefficient, Constant):
@@ -126,10 +126,6 @@ class Expression:
             yield self.coefficient(symbol)
         yield self.constant
 
             yield self.coefficient(symbol)
         yield self.constant
 
-    @property
-    def symbol(self):
-        raise ValueError('not a symbol: {}'.format(self))
-
     def issymbol(self):
         return False
 
     def issymbol(self):
         return False
 
@@ -330,26 +326,26 @@ class Symbol(Expression):
 
     def __new__(cls, name):
         if isinstance(name, Symbol):
 
     def __new__(cls, name):
         if isinstance(name, Symbol):
-            name = name.symbol
+            name = name.name
         elif not isinstance(name, str):
             raise TypeError('name must be a string or a Symbol instance')
         self = object().__new__(cls)
         self._coefficients = {name: 1}
         self._constant = 0
         self._symbols = tuple(name)
         elif not isinstance(name, str):
             raise TypeError('name must be a string or a Symbol instance')
         self = object().__new__(cls)
         self._coefficients = {name: 1}
         self._constant = 0
         self._symbols = tuple(name)
-        self._symbol = name
+        self._name = name
         self._dimension = 1
         return self
 
     @property
         self._dimension = 1
         return self
 
     @property
-    def symbol(self):
-        return self._symbol
+    def name(self):
+        return self._name
 
     def issymbol(self):
         return True
 
     def __repr__(self):
 
     def issymbol(self):
         return True
 
     def __repr__(self):
-        return '{}({!r})'.format(self.__class__.__name__, self._symbol)
+        return '{}({!r})'.format(self.__class__.__name__, self._name)
 
 def symbols(names):
     if isinstance(names, str):
 
 def symbols(names):
     if isinstance(names, str):
index 96b105c..1fe9ac8 100644 (file)
@@ -82,13 +82,6 @@ class TestExpression(unittest.TestCase):
     def test_values(self):
         self.assertCountEqual(self.expr.values(), [1, -2, 3])
 
     def test_values(self):
         self.assertCountEqual(self.expr.values(), [1, -2, 3])
 
-    def test_symbol(self):
-        self.assertEqual(self.x.symbol, 'x')
-        with self.assertRaises(ValueError):
-            self.pi.symbol
-        with self.assertRaises(ValueError):
-            self.expr.symbol
-
     def test_issymbol(self):
         self.assertTrue(self.x.issymbol())
         self.assertFalse(self.pi.issymbol())
     def test_issymbol(self):
         self.assertTrue(self.x.issymbol())
         self.assertFalse(self.pi.issymbol())
@@ -170,6 +163,9 @@ class TestSymbol(unittest.TestCase):
         self.x = Symbol('x')
         self.y = Symbol('y')
 
         self.x = Symbol('x')
         self.y = Symbol('y')
 
+    def test_name(self):
+        self.assertEqual(self.x.name, 'x')
+
     def test_symbols(self):
         self.assertListEqual(list(symbols('x y')), [self.x, self.y])
         self.assertListEqual(list(symbols('x,y')), [self.x, self.y])
     def test_symbols(self):
         self.assertListEqual(list(symbols('x y')), [self.x, self.y])
         self.assertListEqual(list(symbols('x,y')), [self.x, self.y])