altdesktop / i3ipc-python

🐍 An improved Python library to control i3wm and sway.
http://i3ipc-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
851 stars 109 forks source link

Subscribing to event raises TypeError #120

Closed PH111P closed 5 years ago

PH111P commented 5 years ago

In the current version available on Arch Linux (r276.1565263100.8ba5c61), the following code raises an exception, which, to my understanding, should not happen:

import i3ipc
conn = i3ipc.Connection(auto_reconnect=True) 
conn.on('workspace', lambda conn, evt: print('Hello'))
TypeError                                 Traceback (most recent call last)
<ipython-input-5-e048a753152d> in <module>
----> 1 conn.on('workspace', lambda conn, evt: print(''))

/usr/lib/python3.7/site-packages/i3ipc/connection.py in on(self, detailed_event, handler)
    415             raise Exception('event not implemented')
    416 
--> 417         self.subscriptions |= event_type.value
    418 
    419         self._pubsub.subscribe(detailed_event, handler)

TypeError: unsupported operand type(s) for |=: 'Event' and 'int'

Interestingly, this error is not raised if the connection object is created without setting auto_reconnect.

As far as I understand, line 417 should be changed to self.subscriptions |= event_type.

acrisci commented 5 years ago

:+1: