enhancement: Update type hints

This commit is contained in:
jinyu 2024-11-20 06:22:42 +08:00 committed by mathieui
parent 075812adf3
commit d86dccaf85
3 changed files with 35 additions and 31 deletions

View File

@ -167,8 +167,9 @@ processing the same stanza twice.
- **Data:** :py:class:`~.Message` - **Data:** :py:class:`~.Message`
- **Source:** :py:class:`BaseXMPP <.BaseXMPP>` - **Source:** :py:class:`BaseXMPP <.BaseXMPP>`
Makes the contents of message stanzas available whenever one is received. Be Makes the contents of message stanzas that include <body> tags available
sure to check the message type in order to handle error messages. whenever one is received.
Be sure to check the message type to handle error messages appropriately.
message_error message_error
- **Data:** :py:class:`~.Message` - **Data:** :py:class:`~.Message`

View File

@ -414,7 +414,7 @@ class XEP_0045(BasePlugin):
) )
del self.rooms[room] del self.rooms[room]
def set_subject(self, room: JID, subject: str, *, mfrom: Optional[JID] = None): def set_subject(self, room: JidStr, subject: str, *, mfrom: Optional[JID] = None):
"""Set a rooms subject. """Set a rooms subject.
:param room: JID of the room. :param room: JID of the room.
@ -425,7 +425,7 @@ class XEP_0045(BasePlugin):
msg['subject'] = subject msg['subject'] = subject
msg.send() msg.send()
async def get_room_config(self, room: JID, ifrom: Optional[JID] = None, async def get_room_config(self, room: JidStr, ifrom: Optional[JID] = None,
**iqkwargs) -> Form: **iqkwargs) -> Form:
"""Get the room config form in 0004 plugin format. """Get the room config form in 0004 plugin format.
@ -440,7 +440,7 @@ class XEP_0045(BasePlugin):
raise ValueError("Configuration form not found") raise ValueError("Configuration form not found")
return form return form
async def set_room_config(self, room: JID, config: Form, *, async def set_room_config(self, room: JidStr, config: Form, *,
ifrom: Optional[JID] = None, **iqkwargs): ifrom: Optional[JID] = None, **iqkwargs):
"""Send a room config form. """Send a room config form.
@ -453,8 +453,8 @@ class XEP_0045(BasePlugin):
iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom) iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom)
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
async def cancel_config(self, room: JID, *, async def cancel_config(self, room: JidStr, *,
ifrom: Optional[JID] = None, **iqkwargs): ifrom: Optional[JidStr] = None, **iqkwargs):
"""Cancel a requested config form. """Cancel a requested config form.
:param room: Room to cancel the form for. :param room: Room to cancel the form for.
@ -464,8 +464,8 @@ class XEP_0045(BasePlugin):
iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom) iq = self.xmpp.make_iq_set(query, ito=room, ifrom=ifrom)
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
async def destroy(self, room: JID, reason: str = '', altroom: Optional[JID] = None, *, async def destroy(self, room: JidStr, reason: str = '', altroom: Optional[JidStr] = None, *,
ifrom: Optional[JID] = None, **iqkwargs): ifrom: Optional[JidStr] = None, **iqkwargs):
"""Destroy a room. """Destroy a room.
:param room: Room JID to destroy. :param room: Room JID to destroy.
@ -481,10 +481,10 @@ class XEP_0045(BasePlugin):
iq['mucowner_query']['destroy']['reason'] = reason iq['mucowner_query']['destroy']['reason'] = reason
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
async def set_affiliation(self, room: JID, affiliation: MucAffiliation, *, async def set_affiliation(self, room: JidStr, affiliation: MucAffiliation, *,
jid: Optional[JID] = None, jid: Optional[JidStr] = None,
nick: Optional[str] = None, reason: str = '', nick: Optional[str] = None, reason: str = '',
ifrom: Optional[JID] = None, **iqkwargs): ifrom: Optional[JidStr] = None, **iqkwargs):
""" Change room affiliation for a JID or nickname. """ Change room affiliation for a JID or nickname.
:param room: Room to modify. :param room: Room to modify.
@ -508,8 +508,8 @@ class XEP_0045(BasePlugin):
iq['mucadmin_query']['item']['reason'] = reason iq['mucadmin_query']['item']['reason'] = reason
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
async def get_affiliation_list(self, room: JID, affiliation: MucAffiliation, *, async def get_affiliation_list(self, room: JidStr, affiliation: MucAffiliation, *,
ifrom: Optional[JID] = None, **iqkwargs) -> List[JID]: ifrom: Optional[JidStr] = None, **iqkwargs) -> List[JID]:
"""Get a list of JIDs with the specified affiliation """Get a list of JIDs with the specified affiliation
:param room: Room to get affiliations from. :param room: Room to get affiliations from.
@ -520,9 +520,9 @@ class XEP_0045(BasePlugin):
result = await iq.send(**iqkwargs) result = await iq.send(**iqkwargs)
return [item['jid'] for item in result['mucadmin_query']] return [item['jid'] for item in result['mucadmin_query']]
async def send_affiliation_list(self, room: JID, async def send_affiliation_list(self, room: JidStr,
affiliations: List[Tuple[JID, MucAffiliation]], *, affiliations: List[Tuple[JidStr, MucAffiliation]], *,
ifrom: Optional[JID] = None, **iqkwargs): ifrom: Optional[JidStr] = None, **iqkwargs):
"""Send an affiliation delta list. """Send an affiliation delta list.
:param room: Room to send the affiliations to. :param room: Room to send the affiliations to.
@ -536,8 +536,8 @@ class XEP_0045(BasePlugin):
iq['mucadmin_query'].append(item) iq['mucadmin_query'].append(item)
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
async def set_role(self, room: JID, nick: str, role: MucRole, *, async def set_role(self, room: JidStr, nick: str, role: MucRole, *,
reason: str = '', ifrom: Optional[JID] = None, **iqkwargs): reason: str = '', ifrom: Optional[JidStr] = None, **iqkwargs):
""" Change role property of a nick in a room. """ Change role property of a nick in a room.
Typically, roles are temporary (they last only as long as you are in the Typically, roles are temporary (they last only as long as you are in the
room), whereas affiliations are permanent (they last across groupchat room), whereas affiliations are permanent (they last across groupchat
@ -557,8 +557,8 @@ class XEP_0045(BasePlugin):
iq['mucadmin_query']['item']['reason'] = reason iq['mucadmin_query']['item']['reason'] = reason
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
async def get_roles_list(self, room: JID, role: MucRole, *, async def get_roles_list(self, room: JidStr, role: MucRole, *,
ifrom: Optional[JID] = None, **iqkwargs) -> List[str]: ifrom: Optional[JidStr] = None, **iqkwargs) -> List[str]:
""""Get a list of JIDs with the specified role """"Get a list of JIDs with the specified role
:param room: Room to get roles from. :param room: Room to get roles from.
@ -569,8 +569,8 @@ class XEP_0045(BasePlugin):
result = await iq.send(**iqkwargs) result = await iq.send(**iqkwargs)
return [item['nick'] for item in result['mucadmin_query']] return [item['nick'] for item in result['mucadmin_query']]
async def send_role_list(self, room: JID, roles: List[Tuple[str, MucRole]], *, async def send_role_list(self, room: JidStr, roles: List[Tuple[str, MucRole]], *,
ifrom: Optional[JID] = None, **iqkwargs): ifrom: Optional[JidStr] = None, **iqkwargs):
"""Send a role delta list. """Send a role delta list.
:param room: Room to send the roles to. :param room: Room to send the roles to.
@ -584,8 +584,8 @@ class XEP_0045(BasePlugin):
iq['mucadmin_query'].append(item) iq['mucadmin_query'].append(item)
await iq.send(**iqkwargs) await iq.send(**iqkwargs)
def invite(self, room: JID, jid: JID, reason: str = '', *, def invite(self, room: JidStr, jid: JidStr, reason: str = '', *,
mfrom: Optional[JID] = None): mfrom: Optional[JidStr] = None):
""" Invite a jid to a room (mediated invitation). """ Invite a jid to a room (mediated invitation).
:param room: Room to invite the user in. :param room: Room to invite the user in.
@ -598,8 +598,8 @@ class XEP_0045(BasePlugin):
msg['muc']['invite']['reason'] = reason msg['muc']['invite']['reason'] = reason
self.xmpp.send(msg) self.xmpp.send(msg)
def invite_server(self, room: JID, jid: JID, def invite_server(self, room: JidStr, jid: JidStr,
invite_from: JID, reason: str = ''): invite_from: JidStr, reason: str = ''):
"""Send a mediated invite to a user, as a MUC service. """Send a mediated invite to a user, as a MUC service.
.. versionadded:: 1.8.0 .. versionadded:: 1.8.0
@ -617,8 +617,8 @@ class XEP_0045(BasePlugin):
msg['muc']['invite']['reason'] = reason msg['muc']['invite']['reason'] = reason
msg.send() msg.send()
def decline(self, room: JID, jid: JID, reason: str = '', *, def decline(self, room: JidStr, jid: JidStr, reason: str = '', *,
mfrom: Optional[JID] = None): mfrom: Optional[JidStr] = None):
"""Decline a mediated invitation. """Decline a mediated invitation.
:param room: Room the invitation came from. :param room: Room the invitation came from.
@ -631,7 +631,7 @@ class XEP_0045(BasePlugin):
msg['muc']['decline']['reason'] = reason msg['muc']['decline']['reason'] = reason
self.xmpp.send(msg) self.xmpp.send(msg)
def request_voice(self, room: JID, role: str, *, mfrom: Optional[JID] = None): def request_voice(self, room: JidStr, role: str, *, mfrom: Optional[JidStr] = None):
"""Request voice in a moderated room. """Request voice in a moderated room.
:param room: Room to request voice from. :param room: Room to request voice from.
@ -726,7 +726,7 @@ class XEP_0045(BasePlugin):
raise ValueError("Room %s is not joined" % room) raise ValueError("Room %s is not joined" % room)
return list(self.rooms[room].keys()) return list(self.rooms[room].keys())
def get_users_by_affiliation(self, room: JID, affiliation='member', *, ifrom: Optional[JID] = None): def get_users_by_affiliation(self, room: JidStr, affiliation='member', *, ifrom: Optional[JidStr] = None):
# Preserve old API # Preserve old API
if affiliation not in AFFILIATIONS: if affiliation not in AFFILIATIONS:
raise ValueError("Affiliation %s does not exist" % affiliation) raise ValueError("Affiliation %s does not exist" % affiliation)

View File

@ -732,6 +732,9 @@ class ElementBase(object):
return plugin[full_attrib] return plugin[full_attrib]
return plugin return plugin
else: else:
# XXX: This is legacy from SleekXMPP
# We've probably missed the opportunity to fix it
logging.warning("Unknown stanza interface: %s" % full_attrib)
return '' return ''
def __setitem__(self, attrib: str, value: Any) -> Any: def __setitem__(self, attrib: str, value: Any) -> Any: