From b3c0d23e54fe4362097a2b77c34f7bc5b492e2a0 Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Fri, 11 Jul 2014 16:51:06 +0200 Subject: [PATCH 1/1] Improve mapping recognition --- pypol/coordinates.py | 4 ++-- pypol/linexprs.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pypol/coordinates.py b/pypol/coordinates.py index 69d498e..78e8d4a 100644 --- a/pypol/coordinates.py +++ b/pypol/coordinates.py @@ -3,7 +3,7 @@ import numbers import operator from abc import ABC, abstractmethod -from collections import OrderedDict +from collections import OrderedDict, Mapping from .linexprs import Symbol @@ -75,7 +75,7 @@ class Point(Coordinates): """ def __new__(cls, coordinates=None): - if isinstance(coordinates, dict): + if isinstance(coordinates, Mapping): coordinates = coordinates.items() self = object().__new__(cls) self._coordinates = OrderedDict() diff --git a/pypol/linexprs.py b/pypol/linexprs.py index a9f188b..5ec5efd 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): @@ -218,7 +218,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: -- 2.20.1