arvoelke / nengolib

Nengo library of additional extensions
Other
29 stars 6 forks source link

Cannot compare synapse to some types #132

Open arvoelke opened 6 years ago

arvoelke commented 6 years ago
class Foobar(object):
    pass
Lowpass(0.5) != Foobar()
...
/home/arvoelke/.local/lib/python2.7/site-packages/nengolib/signal/system.pyc in sys2tf(sys)
    102 def sys2tf(sys):
    103     """Converts an LTI system in any form to a transfer function."""
--> 104     return _sys2tf[_sys2form(sys)](sys)
    105 
    106 

/home/arvoelke/.local/lib/python2.7/site-packages/nengolib/signal/system.pyc in _sys2form(sys)
     25     elif is_number(sys):
     26         return _NUM
---> 27     elif len(sys) == 2:
     28         return _TF
     29     elif len(sys) == 3:

TypeError: object of type 'Foobar' has no len()

To compare for equality, we cast the other side to a nengolib synapse object. However, an oversight was that if this is not a number or a __len__-able object, it cannot be casted. In fixing this problem we should also throw a better error message when trying to cast such objects.