Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
Replace map() with list comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Mar 9, 2019
1 parent 588c4f1 commit e453d26
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cloudbot/clients/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def cmd(self, command, *params):
:type command: str
:type params: (str)
"""
params = list(map(str, params)) # turn the tuple of parameters into a list
params = [str(param) for param in params] # turn the tuple of parameters into a list
self.send(str(Message(None, None, command, params)))

def send(self, line, log=True):
Expand Down
7 changes: 5 additions & 2 deletions cloudbot/util/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def multi_replace(text, word_dic):
then returns the changed text
:rtype str
"""
rc = re.compile('|'.join(map(re.escape, word_dic)))
rc = re.compile('|'.join(re.escape(word) for word in word_dic))

def translate(match):
return word_dic[match.group(0)]
Expand Down Expand Up @@ -388,7 +388,10 @@ def gen_markdown_table(headers, rows):
rows.insert(0, headers)
rotated = zip(*reversed(rows))

sizes = tuple(map(lambda l: max(max(map(len, l)), 3), rotated))
sizes = tuple(
max(max(len(item) for item in column), 3)
for column in rotated
)
rows.insert(1, tuple(('-' * size) for size in sizes))
lines = [
"| {} |".format(' | '.join(cell.ljust(sizes[i]) for i, cell in enumerate(row)))
Expand Down
5 changes: 3 additions & 2 deletions plugins/chain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
from operator import attrgetter

from sqlalchemy import Table, Column, String, Boolean, PrimaryKeyConstraint

Expand Down Expand Up @@ -221,7 +220,9 @@ def action(msg, target=None):
def chainlist(notice, bot):
"""- Returns the list of commands allowed in 'chain'"""
hooks = [get_hook_from_command(bot, name) for name, allowed in allow_cache.items() if allowed]
cmds = itertools.chain.from_iterable(map(attrgetter("aliases"), hooks))
cmds = itertools.chain.from_iterable(
_hook.aliases for _hook in hooks
)
cmds = sorted(cmds)
for part in chunk_str(", ".join(cmds)):
notice(part)
3 changes: 2 additions & 1 deletion plugins/core/check_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def format_conn(conn):
def list_conns(bot):
"""- Lists all current connections and their status"""
conns = ', '.join(
map(format_conn, bot.connections.values())
format_conn(conn)
for conn in bot.connections.values()
)
return "Current connections: {}".format(conns)

Expand Down
10 changes: 6 additions & 4 deletions plugins/core/core_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
logger = logging.getLogger("cloudbot")


def ci_list_check(value, data):
return value.lower() in (item.lower() for item in data)


@hook.periodic(600)
def task_clear():
for uid, _bucket in buckets.copy().items():
Expand All @@ -24,12 +28,10 @@ async def sieve_suite_cb(bot, event, _hook):
acl = conn.config.get('acls', {}).get(_hook.function_name)
if acl:
if 'deny-except' in acl:
allowed_channels = list(map(str.lower, acl['deny-except']))
if event.chan.lower() not in allowed_channels:
if not ci_list_check(event.chan, acl['deny-except']):
return None
if 'allow-except' in acl:
denied_channels = list(map(str.lower, acl['allow-except']))
if event.chan.lower() in denied_channels:
if ci_list_check(event.chan, acl['allow-except']):
return None

# check disabled_commands
Expand Down
2 changes: 1 addition & 1 deletion plugins/gaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def dice(text, notice):
try:
if count > 0:
d = n_rolls(count, side)
rolls += list(map(str, d))
rolls += [str(x) for x in d]
total += sum(d)
else:
d = n_rolls(-count, side)
Expand Down
2 changes: 1 addition & 1 deletion plugins/tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,5 +452,5 @@ def list_tell_ignores(conn, nick):
return "You are not ignoring tells from any users"

return "You are ignoring tell from: {}".format(
', '.join(map(repr, ignores))
', '.join(repr(ignore) for ignore in ignores)
)

0 comments on commit e453d26

Please sign in to comment.