X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/26837dbbeb8e37f8ee393115e879e6d94a1a79e5..493e8f7bd66fca81d9d670caf058e0a11306e0fe:/pypol/linexprs.py?ds=inline diff --git a/pypol/linexprs.py b/pypol/linexprs.py index a9f188b..b23eea8 100644 --- a/pypol/linexprs.py +++ b/pypol/linexprs.py @@ -3,7 +3,7 @@ import functools import numbers import re -from collections import OrderedDict, defaultdict +from collections import OrderedDict, defaultdict, Mapping from fractions import Fraction, gcd @@ -45,7 +45,7 @@ class Expression: return Expression.fromstring(coefficients) if coefficients is None: return Rational(constant) - if isinstance(coefficients, dict): + if isinstance(coefficients, Mapping): coefficients = coefficients.items() for symbol, coefficient in coefficients: if not isinstance(symbol, Symbol): @@ -65,14 +65,12 @@ class Expression: if isinstance(coefficient, Rational): coefficient = coefficient.constant if not isinstance(coefficient, numbers.Rational): - raise TypeError('coefficients must be rational numbers ' - 'or Rational instances') + raise TypeError('coefficients must be Rational instances') self._coefficients[symbol] = coefficient if isinstance(constant, Rational): constant = constant.constant if not isinstance(constant, numbers.Rational): - raise TypeError('constant must be a rational number ' - 'or a Rational instance') + raise TypeError('constant must be a Rational instance') self._constant = constant self._symbols = tuple(self._coefficients) self._dimension = len(self._symbols) @@ -218,7 +216,7 @@ class Expression: def subs(self, symbol, expression=None): if expression is None: - if isinstance(symbol, dict): + if isinstance(symbol, Mapping): symbol = symbol.items() substitutions = symbol else: