Skip to content

Commit

Permalink
style: replace format() with f-strings (#1667)
Browse files Browse the repository at this point in the history
* style: replace format() with f-strings

* style: converting more tests to f-strings

* docs: update examples

* style: another round of conversions

* docs: add details to CHANGES
  • Loading branch information
sijis authored Oct 30, 2023
1 parent cb9e671 commit 0080eff
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fixes:
- chore: update repos.json (#1660)
- docs: add readthedocs yaml config (#1661)
- fix: broken integration tests (#1668)
- style: replace format() with f-strings (#1667)


v6.1.9 (2022-06-11)
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/plugin_development/webhooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ which contains all the details about the actual request:
@webhook(raw=True)
def test(self, request):
user_agent = request.headers.get("user-agent", "Unknown")
return "Your user-agent is {}".format(user_agent)
return f"Your user-agent is {user_agent}"
Returning custom headers and status codes
Expand Down
4 changes: 1 addition & 3 deletions errbot/botplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ def append_args(self, args, kwargs):
update_wrapper(self.definition, args, kwargs)
else:
log.warning(
"Attempting to append arguments to {} isn't supported.".format(
self.definition
)
f"Attempting to append arguments to {self.definition} isn't supported."
)


Expand Down
4 changes: 1 addition & 3 deletions errbot/core_plugins/vcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def _get_version(self):
# noinspection PyBroadException
try:
possible_versions = requests.get(HOME).json()
version = possible_versions.get(
"python{}".format(major_py_version), VERSION
)
version = possible_versions.get(f"python{major_py_version}", VERSION)
self.log.debug("Latest Errbot version is: %s", version)
except (HTTPError, URLError, ConnectionError, JSONDecodeError):
self.log.info("Could not establish connection to retrieve latest version.")
Expand Down
6 changes: 3 additions & 3 deletions tests/base_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,9 @@ def test_access_controls(dummy_backend):
dummy_backend.bot_config.ACCESS_CONTROLS = test.get("acl", {})
dummy_backend.bot_config.BOT_ADMINS = test.get("bot_admins", ())
logger = logging.getLogger(__name__)
logger.info("** message: {}".format(test["message"].body))
logger.info("** bot_admins: {}".format(dummy_backend.bot_config.BOT_ADMINS))
logger.info("** acl: {!r}".format(dummy_backend.bot_config.ACCESS_CONTROLS))
logger.info(f"** message: {test['message'].body}")
logger.info(f"** bot_admins: {dummy_backend.bot_config.BOT_ADMINS}")
logger.info(f"** acl: {dummy_backend.bot_config.ACCESS_CONTROLS}")
logger.info(
"** acl_default: {!r}".format(
dummy_backend.bot_config.ACCESS_CONTROLS_DEFAULT
Expand Down
2 changes: 1 addition & 1 deletion tests/commandnotfound_plugin/commandnotfound.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def command_not_found(self, msg, cmd, args, dry_run, emptycmd=False):
if not emptycmd:
return msg, cmd, args

return "Command fell through: {}".format(msg)
return f"Command fell through: {msg}"
8 changes: 3 additions & 5 deletions tests/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def test_plugin_cycle(testbot):
]

for plugin in plugins:
testbot.assertInCommand(
"!repos install {0}".format(plugin), "Installing {0}...".format(plugin)
),
testbot.assertInCommand(f"!repos install {plugin}", f"Installing {plugin}..."),
assert (
"A new plugin repository has been installed correctly from errbotio/err-helloworld"
in testbot.pop_message(timeout=60)
Expand Down Expand Up @@ -231,7 +229,7 @@ def test_webserver_webhook_test(testbot):

def test_activate_reload_and_deactivate(testbot):
for command in ("activate", "reload", "deactivate"):
testbot.push_message("!plugin {}".format(command))
testbot.push_message(f"!plugin {command}")
m = testbot.pop_message()
assert "Please tell me which of the following plugins to" in m
assert "ChatRoom" in m
Expand Down Expand Up @@ -350,7 +348,7 @@ def test_callback_no_command(testbot):
)

cmd = "!this_is_not_a_real_command_at_all"
expected_str = "Command fell through: {}".format(cmd)
expected_str = f"Command fell through: {cmd}"

testbot.exec_command("!plugin deactivate CommandNotFoundFilter")
testbot.bot.plugin_manager._extra_plugin_dir = extra_plugin_dir
Expand Down
6 changes: 3 additions & 3 deletions tests/room_plugin/roomtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def activate(self):

def callback_room_joined(self, room, user, invited_by):
log.info("join")
self.events.put("callback_room_joined {!s}".format(room))
self.events.put(f"callback_room_joined {room}")

def callback_room_left(self, room, user, kicked_by):
self.events.put("callback_room_left {!s}".format(room))
self.events.put(f"callback_room_left {room}")

def callback_room_topic(self, room):
self.events.put("callback_room_topic {}".format(room.topic))
self.events.put(f"callback_room_topic {room.topic}")

def purge(self):
log.info("purge")
Expand Down

0 comments on commit 0080eff

Please sign in to comment.