TypeError: integer argument expected, got float

Bug #752699 reported by Roberto
22
This bug affects 3 people
Affects Status Importance Assigned to Milestone
python-uinput
Invalid
Undecided
Unassigned

Bug Description

Thanks in advance...
I installed libsuinput-0.4, python-uinput-0.5, pytuio-0.1 and I tried tuiototouch.py in ubuntu 11.04.
Is there something wrong in __init__.py ?

sudo python tuiototouch.py

type :1 code : 330 value : 0
type :1 code : 330 value : 1
type :3 code :0 value :895
Traceback (most recent call last):
  File "tuiototouch.py", line 121, in <module>
    device.display()
  File "tuiototouch.py", line 92, in display
    self.device.emit(uinput.EV_ABS, uinput.ABS_X, self.x_mouse, syn=False)
  File "/usr/local/lib/python2.7/dist-packages/uinput/__init__.py", line 174, in emit
    suinput.uinput_write(self.__uinput_fd, ev_type, ev_code, ev_value)
TypeError: integer argument expected, got float

Revision history for this message
a (tuomasjjrasanen) wrote :

Hi and thank you for reporting this!

It seems that your tuiototouch.py on line 92 is passing a float argument (self.x_mouse). Uinput expects only integers.

I think that the int-conversion could be done under the hood in suinput. So perhaps suinput should make sure that ev_value is integer before it passes it to the uinput-system.

So there are two possible solutions. I could either

  - document the integer requirement for uinput.Device.emit()

or

 - allow any numerical type and typecast it to integer in suinput

I'm not sure right away which is better, I'll think about it for a while.

Meanwhile, I think you can fix this by typecasting self.x_mouse to int in tuiototouch.py: int(self.x_mouse).

Revision history for this message
Linus Seelinger (s-linus) wrote :

self.x_mouse is not the only place where there needs to be a typecast. after adding these typecasts, it works well.

Yet, there is another problem on ubuntu 11.04:

Traceback (most recent call last):
  File "/home/gabriel/Arbeitsfläche/tuiototouchbridge/tuiototouch.py", line 110, in <module>
    tracking=tuio.Tracking()
  File "/usr/local/lib/python2.7/dist-packages/tuio/__init__.py", line 29, in __init__
    self.open_socket()
  File "/usr/local/lib/python2.7/dist-packages/tuio/__init__.py", line 39, in open_socket
    self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
AttributeError: 'module' object has no attribute 'SO_REUSEPORT'

By replacing 'SO_REUSEPORT' by 'SO_REUSEADDR', I could make it work.

Changed in python-uinput:
status: New → Confirmed
Revision history for this message
Dave Gordon (python-bugz) wrote :

Probably down to a change in Python 2.7. Up until 2.6, if you passed a float to a function that was defined as taking an int, the float would automatically be converted, though possibly with a DeprecationWarnng. In 2.7 (and Python 3000) it's now a TypeError. So, you have to put in an explicit conversion to int wherever this occurs.

There are quite a lot of packages affected by this!

Dave

a (tuomasjjrasanen)
Changed in python-uinput:
importance: Undecided → Medium
assignee: nobody → Tuomas Jorma Juhani Räsänen (tuos)
milestone: none → 0.6
Revision history for this message
a (tuomasjjrasanen) wrote :

It's an error to pass a float value as event descriptor. Therefore I'm marking this bug as invalid. Python-uinput should not make an implicit type cast to hide type errors in the application logic.

Changed in python-uinput:
status: Confirmed → Invalid
importance: Medium → Undecided
assignee: Tuomas Jorma Juhani Räsänen (tuomasjjrasanen) → nobody
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.