Misleading error message if python float value if written to int attribute for python >= 3.10
Starting from 3.10 PyLong_AsLong was changed:
Changed in version 3.10: This function will no longer use
__int__().
We use PyLong_AsLong in binding to convert python value to c:
As the result, when use tries to write float value to int attribute it gets:
>>> import tango
>>> dev = tango.DeviceProxy("sys/tg_test/1")
>>> a = 5.5
>>> tango.utils.is_number(a)
True
>>> dev.short_scalar = a
Traceback (most recent call last):
File "/home/matveyev/.local/share/JetBrains/Toolbox/apps/pycharm-professional/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
File "<input>", line 1, in <module>
File "/home/matveyev/pytango/tango/device_proxy.py", line 510, in __DeviceProxy__setattr
return __set_attribute_value(self, name, value)
File "/home/matveyev/pytango/tango/device_proxy.py", line 442, in __set_attribute_value
return self.write_attribute(name, value)
File "/home/matveyev/pytango/tango/green.py", line 234, in greener
return executor.run(fn, args, kwargs, wait=wait, timeout=timeout)
File "/home/matveyev/pytango/tango/green.py", line 124, in run
return fn(*args, **kwargs)
File "/home/matveyev/pytango/tango/device_proxy.py", line 1964, in __DeviceProxy__write_attribute
return self._write_attribute(*args, **kwargs)
TypeError: Expecting a numeric type but it is not. If you use a numpy type instead of python core types, then it must exactly match (ex: numpy.int32 for PyTango.DevLong)
Which is confusing, since both "float" and "int" are python core numeric types
Edited by Anton Joubert