qwertyquerty / pypresence

A complete Discord IPC and Rich Presence wrapper library in Python!
https://qwertyquerty.github.io/pypresence/html/index.html
MIT License
652 stars 76 forks source link

Fix bug on baseclient.py #242

Open DonLarry opened 4 months ago

DonLarry commented 4 months ago

Line 55 says:

loop.set_exception_handler(err_handler)

If loop is None and handler is not None when the class constructor is called, then:

  1. loop remains None at line 55, and we will get an AttributeError saying that NoneType has no attribute set_exception_handler.
  2. self.loop will be updated when update_event_loop method is invoked at line 31.

So, we should use self.loop or assign self.loop to loop before using it.

NikOverflow commented 4 months ago

Line 55 says:

loop.set_exception_handler(err_handler)

If loop is None and handler is not None when the class constructor is called, then:

  1. loop remains None at line 55, and we will get an AttributeError saying that NoneType has no attribute set_exception_handler.
  2. self.loop will be updated when update_event_loop method is invoked at line 31.

So, we should use self.loop or assign self.loop to loop before using it.

Do you have a proof of concept that calls the exception?

DonLarry commented 4 months ago

Do you have a proof of concept that calls the exception?

Yes, I do. Try to run this simple code for example:

from pypresence import Presence

def f(a, b):
    pass

Presence(client_id=123, handler=f)

I'm getting the following error:

Traceback (most recent call last):
  File "...\a.py", line 6, in <module>
    Presence(client_id=123, handler=f)
  File "...\venv\Lib\site-packages\pypresence\presence.py", line 13, in __init__
    super().__init__(*args, **kwargs)
  File "...\venv\Lib\site-packages\pypresence\baseclient.py", line 55, in __init__
    loop.set_exception_handler(err_handler)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'set_exception_handler'