You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering a TypeError in the pydle library when running my IRC bot. The error occurs because the _create_user method, which is synchronous, is being called with await in asynchronous methods like _sync_user and _rename_user. This leads to an exception since you cannot await a non-coroutine function.
Error Details
Here is the traceback of the error:
TypeError: object NoneType can't be used in 'await' expression
This occurs when the bot receives certain IRC messages and attempts to handle user synchronization.
Code Snippets
From client.py:
def_create_user(self, nickname):
# Servers are NOT users.ifnotnicknameor'.'innickname:
returnself.users[nickname] = {
'nickname': nickname,
'username': None,
'realname': None,
'hostname': None
}
asyncdef_sync_user(self, nick, metadata):
# Create user in database.ifnicknotinself.users:
awaitself._create_user(nick) # <-- This causes the TypeErrorifnicknotinself.users:
returnself.users[nick].update(metadata)
asyncdef_rename_user(self, user, new):
ifuserinself.users:
self.users[new] =self.users[user]
self.users[new]['nickname'] =newdelself.users[user]
else:
awaitself._create_user(new) # <-- This causes the TypeErrorifnewnotinself.users:
returnforchinself.channels.values():
# Rename user in channel list.ifuserinch['users']:
ch['users'].discard(user)
ch['users'].add(new)
In the code above, _create_user is defined as a synchronous function using def, but it's being called with await in the asynchronous methods _sync_user and _rename_user. This mismatch leads to the TypeError.
Steps to Reproduce
Install pydle in a Python 3.9 environment.
Run an IRC bot that connects to a server and handles user joins and messages.
When the bot receives certain messages that trigger _sync_user or _rename_user, the error occurs.
Proposed Solutions
Option 1: Remove await from Calls to _create_user
Since _create_user is synchronous, it should not be awaited. Updating the methods as follows resolves the issue:
However, this requires reviewing all calls to _create_user to ensure they are awaited appropriately.
Additional Information
Python Version: 3.9
Pydle Version: (Please specify the version you're using)
Environment: Running in a miniconda3 environment
Request
Could the maintainers consider adjusting the method definitions or the calls to _create_user to ensure consistency between synchronous and asynchronous functions? This would prevent the TypeError and improve compatibility with asynchronous code.
(Issue largely written using OpenAI's o1-preview model.)
The text was updated successfully, but these errors were encountered:
Description
I'm encountering a
TypeError
in thepydle
library when running my IRC bot. The error occurs because the_create_user
method, which is synchronous, is being called withawait
in asynchronous methods like_sync_user
and_rename_user
. This leads to an exception since you cannotawait
a non-coroutine function.Error Details
Here is the traceback of the error:
This occurs when the bot receives certain IRC messages and attempts to handle user synchronization.
Code Snippets
From
client.py
:In the code above,
_create_user
is defined as a synchronous function usingdef
, but it's being called withawait
in the asynchronous methods_sync_user
and_rename_user
. This mismatch leads to theTypeError
.Steps to Reproduce
pydle
in a Python 3.9 environment._sync_user
or_rename_user
, the error occurs.Proposed Solutions
Option 1: Remove
await
from Calls to_create_user
Since
_create_user
is synchronous, it should not be awaited. Updating the methods as follows resolves the issue:Option 2: Make
_create_user
AsynchronousAlternatively, if there is a need for
_create_user
to be asynchronous (e.g., future asynchronous operations), it can be defined as an async function:However, this requires reviewing all calls to
_create_user
to ensure they are awaited appropriately.Additional Information
miniconda3
environmentRequest
Could the maintainers consider adjusting the method definitions or the calls to
_create_user
to ensure consistency between synchronous and asynchronous functions? This would prevent theTypeError
and improve compatibility with asynchronous code.(Issue largely written using OpenAI's
o1-preview
model.)The text was updated successfully, but these errors were encountered: