Skip to content

Commit 5a3bae3

Browse files
committed
Upgrade syntax to 3.8
1 parent 948b52e commit 5a3bae3

File tree

124 files changed

+452
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+452
-495
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ repos:
4848
hooks:
4949
- id: python-no-eval
5050
- id: python-no-log-warn
51+
- repo: https://github.com/asottile/pyupgrade
52+
rev: df17dfa3911b81b4a27190b0eea5b1debc7ffa0a # frozen: v3.15.1
53+
hooks:
54+
- id: pyupgrade
55+
args:
56+
- "--py38-plus"
57+
5158
- repo: local
5259
hooks:
5360
- id: mypy

cloudbot/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def exit_gracefully(signum, frame):
4242
stopped_while_restarting = True
4343
else:
4444
async_util.run_coroutine_threadsafe(
45-
_bot.stop("Killed (Received SIGINT {})".format(signum)),
45+
_bot.stop(f"Killed (Received SIGINT {signum})"),
4646
_bot.loop,
4747
)
4848

cloudbot/bot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ def add_hook(hook, _event, _run_before=False):
431431
command for command, plugin in potential_matches
432432
)
433433
txt_list = formatting.get_text_list(commands)
434-
event.notice(
435-
"Possible matches: {}".format(txt_list)
436-
)
434+
event.notice(f"Possible matches: {txt_list}")
437435

438436
if event.type in (EventType.message, EventType.action):
439437
# Regex hooks

cloudbot/clients/irc.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
irc_nick_re = re.compile(r"[A-Za-z0-9^{}\[\]\-`_|\\]+")
2222

2323
irc_bad_chars = "".join(
24-
(
25-
c
26-
for c in (chr(x) for x in chain(range(0, 32), range(127, 160)))
27-
if c not in colors.IRC_FORMATTING_DICT.values() and c != "\1"
28-
)
24+
c
25+
for c in (chr(x) for x in chain(range(0, 32), range(127, 160)))
26+
if c not in colors.IRC_FORMATTING_DICT.values() and c != "\1"
2927
)
3028

31-
irc_clean_re = re.compile("[{}]".format(re.escape(irc_bad_chars)))
29+
irc_clean_re = re.compile(f"[{re.escape(irc_bad_chars)}]")
3230

3331

3432
def irc_clean(dirty: str) -> str:
@@ -205,9 +203,9 @@ def make_ssl_context(self, conn_config):
205203

206204
def describe_server(self):
207205
if self.use_ssl:
208-
return "+{}:{}".format(self.server, self.port)
206+
return f"+{self.server}:{self.port}"
209207

210-
return "{}:{}".format(self.server, self.port)
208+
return f"{self.server}:{self.port}"
211209

212210
async def auto_reconnect(self):
213211
"""
@@ -232,7 +230,7 @@ async def try_connect(self):
232230
self.name,
233231
self.describe_server(),
234232
)
235-
except (socket.error, socket.gaierror, OSError, ssl.SSLError):
233+
except (OSError, socket.gaierror, ssl.SSLError):
236234
logger.error(
237235
"[%s] Error occurred while connecting to %s (%s)",
238236
self.name,
@@ -365,7 +363,7 @@ def ctcp(self, target, ctcp_type, text):
365363
"""
366364
Makes the bot send a PRIVMSG CTCP of type <ctcp_type> to the target
367365
"""
368-
out = "\x01{} {}\x01".format(ctcp_type, text)
366+
out = f"\x01{ctcp_type} {text}\x01"
369367
self.cmd("PRIVMSG", target, out)
370368

371369
def cmd(self, command, *params):

cloudbot/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def reply(self, *messages, target=None):
264264
self.conn.message(target, *messages)
265265
else:
266266
self.conn.message(
267-
target, "({}) {}".format(self.nick, messages[0]), *messages[1:]
267+
target, f"({self.nick}) {messages[0]}", *messages[1:]
268268
)
269269

270270
def action(self, message, target=None):

cloudbot/hook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def add_hook(self, alias_param, kwargs):
7070
self.main_alias = alias_param[0]
7171
for alias in alias_param:
7272
if not valid_command_re.match(alias):
73-
raise ValueError("Invalid command name {}".format(alias))
73+
raise ValueError(f"Invalid command name {alias}")
7474
self.aliases.update(alias_param)
7575

7676

@@ -145,7 +145,7 @@ def add_hook(self, trigger_param, kwargs):
145145

146146
class _CapHook(_Hook):
147147
def __init__(self, func, _type):
148-
super().__init__(func, "on_cap_{}".format(_type))
148+
super().__init__(func, f"on_cap_{_type}")
149149
self.caps = set()
150150

151151
def add_hook(self, caps, kwargs):

cloudbot/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ async def load_plugin(self, path):
228228
if self.get_plugin(file_path):
229229
await self.unload_plugin(file_path)
230230

231-
module_name = "plugins.{}".format(title)
231+
module_name = f"plugins.{title}"
232232
try:
233233
plugin_module = self._load_mod(module_name)
234234
except Exception:

cloudbot/plugin_hooks.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, _type, plugin, func_hook):
6767

6868
@property
6969
def description(self):
70-
return "{}:{}".format(self.plugin.title, self.function_name)
70+
return f"{self.plugin.title}:{self.function_name}"
7171

7272
def __repr__(self):
7373
parts = [
@@ -77,7 +77,7 @@ def __repr__(self):
7777
("single_thread", self.single_thread),
7878
("threaded", self.threaded),
7979
]
80-
return ", ".join("{}: {}".format(k, v) for k, v in parts)
80+
return ", ".join(f"{k}: {v}" for k, v in parts)
8181

8282

8383
class CommandHook(Hook):
@@ -180,7 +180,7 @@ def __init__(self, plugin, sieve_hook):
180180
super().__init__("sieve", plugin, sieve_hook)
181181

182182
def __repr__(self):
183-
return "Sieve[{}]".format(Hook.__repr__(self))
183+
return f"Sieve[{Hook.__repr__(self)}]"
184184

185185
def __str__(self):
186186
return "sieve {} from {}".format(
@@ -213,7 +213,7 @@ def __init__(self, plugin, on_start_hook):
213213
super().__init__("on_start", plugin, on_start_hook)
214214

215215
def __repr__(self):
216-
return "On_start[{}]".format(Hook.__repr__(self))
216+
return f"On_start[{Hook.__repr__(self)}]"
217217

218218
def __str__(self):
219219
return "on_start {} from {}".format(
@@ -226,7 +226,7 @@ def __init__(self, plugin, on_stop_hook):
226226
super().__init__("on_stop", plugin, on_stop_hook)
227227

228228
def __repr__(self):
229-
return "On_stop[{}]".format(Hook.__repr__(self))
229+
return f"On_stop[{Hook.__repr__(self)}]"
230230

231231
def __str__(self):
232232
return "on_stop {} from {}".format(
@@ -236,7 +236,7 @@ def __str__(self):
236236

237237
class CapHook(Hook):
238238
def __init__(self, _type, plugin, base_hook):
239-
super().__init__("on_cap_{}".format(_type), plugin, base_hook)
239+
super().__init__(f"on_cap_{_type}", plugin, base_hook)
240240

241241
self.caps = base_hook.caps
242242

@@ -267,7 +267,7 @@ def __init__(self, plugin, sieve_hook):
267267
super().__init__("on_connect", plugin, sieve_hook)
268268

269269
def __repr__(self):
270-
return "{name}[{base!r}]".format(name=self.type, base=super())
270+
return f"{self.type}[{super()!r}]"
271271

272272
def __str__(self):
273273
return "{name} {func} from {file}".format(
@@ -280,7 +280,7 @@ def __init__(self, plugin, out_hook):
280280
super().__init__("irc_out", plugin, out_hook)
281281

282282
def __repr__(self):
283-
return "Irc_Out[{}]".format(Hook.__repr__(self))
283+
return f"Irc_Out[{Hook.__repr__(self)}]"
284284

285285
def __str__(self):
286286
return "irc_out {} from {}".format(
@@ -293,7 +293,7 @@ def __init__(self, plugin, out_hook):
293293
super().__init__("post_hook", plugin, out_hook)
294294

295295
def __repr__(self):
296-
return "Post_hook[{}]".format(Hook.__repr__(self))
296+
return f"Post_hook[{Hook.__repr__(self)}]"
297297

298298
def __str__(self):
299299
return "post_hook {} from {}".format(
@@ -319,7 +319,7 @@ def __init__(self, plugin, perm_hook):
319319
self.perms = perm_hook.perms
320320

321321
def __repr__(self):
322-
return "PermHook[{}]".format(Hook.__repr__(self))
322+
return f"PermHook[{Hook.__repr__(self)}]"
323323

324324
def __str__(self):
325325
return "perm hook {} from {}".format(

cloudbot/reloader.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ async def _unload(self, path):
7474

7575
class ConfigReloader(Reloader):
7676
def __init__(self, bot):
77-
super().__init__(
78-
bot, ConfigEventHandler, "*{}".format(bot.config.filename)
79-
)
77+
super().__init__(bot, ConfigEventHandler, f"*{bot.config.filename}")
8078

8179
def reload(self, path):
8280
if self.bot.running:

cloudbot/util/formatting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def pluralize_suffix(num=0, text="", suffix="s"):
265265

266266

267267
def pluralize_select(count, single, plural):
268-
return "{:,} {}".format(count, single if count == 1 else plural)
268+
return f"{count:,} {single if count == 1 else plural}"
269269

270270

271271
pluralise_select = pluralize_select
@@ -369,7 +369,7 @@ def get_text_list(list_, last_word="or"):
369369
if len(list_) == 1:
370370
return list_[0]
371371

372-
return "%s %s %s" % (
372+
return "{} {} {}".format(
373373
# Translators: This string is used as a separator between list elements
374374
", ".join([i for i in list_][:-1]),
375375
last_word,

0 commit comments

Comments
 (0)