Fix users.get(..., allow_multiple=True) to always return a list
This commit is contained in:
parent
6bf12520f1
commit
33563da1eb
25
src/users.py
25
src/users.py
@ -59,28 +59,27 @@ def _get(nick=None, ident=None, host=None, realname=None, account=None, *, allow
|
|||||||
sentinel = object()
|
sentinel = object()
|
||||||
|
|
||||||
temp = User(sentinel, nick, ident, host, realname, account)
|
temp = User(sentinel, nick, ident, host, realname, account)
|
||||||
if temp.client is not sentinel:
|
if temp.client is not sentinel: # actual client
|
||||||
return temp # actual client
|
return [temp] if allow_multiple else temp
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if user == temp:
|
if user == temp:
|
||||||
potential.append(user)
|
potential.append(user)
|
||||||
|
|
||||||
if not allow_multiple and len(potential) > 1:
|
|
||||||
raise ValueError("More than one user matches: " +
|
|
||||||
_arg_msg.format(nick, ident, host, realname, account, allow_bot))
|
|
||||||
|
|
||||||
|
|
||||||
if not potential and not allow_multiple and not allow_none:
|
|
||||||
raise KeyError(_arg_msg.format(nick, ident, host, realname, account, allow_bot))
|
|
||||||
|
|
||||||
if allow_multiple:
|
if allow_multiple:
|
||||||
return potential
|
return potential
|
||||||
|
|
||||||
if not potential: # allow_none
|
if len(potential) == 1:
|
||||||
return None
|
return potential[0]
|
||||||
|
|
||||||
return potential[0]
|
if len(potential) > 1:
|
||||||
|
raise ValueError("More than one user matches: " +
|
||||||
|
_arg_msg.format(nick, ident, host, realname, account, allow_bot))
|
||||||
|
|
||||||
|
if not allow_none:
|
||||||
|
raise KeyError(_arg_msg.format(nick, ident, host, realname, account, allow_bot))
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def get(nick, *stuff, **morestuff): # backwards-compatible API - kill this as soon as possible!
|
def get(nick, *stuff, **morestuff): # backwards-compatible API - kill this as soon as possible!
|
||||||
var.USERS[nick] # _user(nick) evaluates lazily, so check eagerly if the nick exists
|
var.USERS[nick] # _user(nick) evaluates lazily, so check eagerly if the nick exists
|
||||||
|
Loading…
x
Reference in New Issue
Block a user