seznam / fastrpc

FastRPC library
http://seznam.github.io/frpc
GNU Lesser General Public License v2.1
46 stars 46 forks source link

DateTime TypeError in comparison #22

Closed schunka closed 8 years ago

schunka commented 8 years ago

Whenever you try to compare DateTime object to some other type it throws: TypeError: arg #2 is not a DateTime, it is ...

import fastrpc
d=fastrpc.DateTime()
d =! ''

Reproducible in versions 5.1.0 and higher This is really unexpected behavior and from my point of view a bug. In version 5.0.9 and lower comparison behaves expectedly, like any other data type in python. If this is desired behavior, it should be documented and pinpointed for its "non pythonian way" characteristic.

volca02 commented 8 years ago

Most likely caused by 30c95243ac04bb981de9a2cf8db2b63a6edd9b17, which replaced tp_compare with tp_richcompare

volca02 commented 8 years ago

The original tp_compare was not implemented well. It assumes both arguments are DateTime objects, which is not true for the mentioned case, and probably lead to undefined behavior silently.

A python way would be to return False when comparing different types for equality, and raise TypeError for other operations.