projects
/
linpy.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
98d00e8
)
Better implementation of _polymorphic_operator
author
Vivien Maisonneuve
<v.maisonneuve@gmail.com>
Wed, 28 May 2014 16:30:20 +0000
(18:30 +0200)
committer
Vivien Maisonneuve
<v.maisonneuve@gmail.com>
Wed, 28 May 2014 16:30:20 +0000
(18:30 +0200)
pypol/linear.py
patch
|
blob
|
history
diff --git
a/pypol/linear.py
b/pypol/linear.py
index
fabf2a2
..
a5f55fa
100644
(file)
--- a/
pypol/linear.py
+++ b/
pypol/linear.py
@@
-26,13
+26,14
@@
def _polymorphic_method(func):
return wrapper
def _polymorphic_operator(func):
return wrapper
def _polymorphic_operator(func):
+ # A polymorphic operator should call a polymorphic method, hence we just
+ # have to test the left operand.
@functools.wraps(func)
def wrapper(a, b):
if isinstance(a, numbers.Rational):
a = constant(a)
@functools.wraps(func)
def wrapper(a, b):
if isinstance(a, numbers.Rational):
a = constant(a)
- if isinstance(b, numbers.Rational):
- b = constant(b)
- if isinstance(a, Expression) and isinstance(b, Expression):
+ return func(a, b)
+ elif isinstance(a, Expression):
return func(a, b)
raise TypeError('arguments must be linear expressions')
return wrapper
return func(a, b)
raise TypeError('arguments must be linear expressions')
return wrapper