pyupgrade: Reformat with --py36-plus.
This includes mainly fixes of string literals using f-strings or .format(...), as well as unpacking of list comprehensions.
This commit is contained in:
parent
e27ac0ddbe
commit
9ce7c52a10
78 changed files with 356 additions and 389 deletions
|
@ -77,7 +77,7 @@ def matrix_to_zulip(
|
|||
"""
|
||||
content = get_message_content_from_event(event, no_noise)
|
||||
|
||||
zulip_bot_user = "@%s:matrix.org" % (matrix_config["username"],)
|
||||
zulip_bot_user = "@{}:matrix.org".format(matrix_config["username"])
|
||||
# We do this to identify the messages generated from Zulip -> Matrix
|
||||
# and we make sure we don't forward it again to the Zulip stream.
|
||||
not_from_zulip_bot = event["sender"] != zulip_bot_user
|
||||
|
@ -228,9 +228,7 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, str]]:
|
|||
|
||||
def write_sample_config(target_path: str, zuliprc: Optional[str]) -> None:
|
||||
if os.path.exists(target_path):
|
||||
raise Bridge_ConfigException(
|
||||
"Path '{}' exists; not overwriting existing file.".format(target_path)
|
||||
)
|
||||
raise Bridge_ConfigException(f"Path '{target_path}' exists; not overwriting existing file.")
|
||||
|
||||
sample_dict = OrderedDict(
|
||||
(
|
||||
|
@ -262,7 +260,7 @@ def write_sample_config(target_path: str, zuliprc: Optional[str]) -> None:
|
|||
|
||||
if zuliprc is not None:
|
||||
if not os.path.exists(zuliprc):
|
||||
raise Bridge_ConfigException("Zuliprc file '{}' does not exist.".format(zuliprc))
|
||||
raise Bridge_ConfigException(f"Zuliprc file '{zuliprc}' does not exist.")
|
||||
|
||||
zuliprc_config = configparser.ConfigParser()
|
||||
try:
|
||||
|
@ -293,10 +291,10 @@ def main() -> None:
|
|||
try:
|
||||
write_sample_config(options.sample_config, options.zuliprc)
|
||||
except Bridge_ConfigException as exception:
|
||||
print("Could not write sample config: {}".format(exception))
|
||||
print(f"Could not write sample config: {exception}")
|
||||
sys.exit(1)
|
||||
if options.zuliprc is None:
|
||||
print("Wrote sample configuration to '{}'".format(options.sample_config))
|
||||
print(f"Wrote sample configuration to '{options.sample_config}'")
|
||||
else:
|
||||
print(
|
||||
"Wrote sample configuration to '{}' using zuliprc file '{}'".format(
|
||||
|
@ -312,7 +310,7 @@ def main() -> None:
|
|||
try:
|
||||
config = read_configuration(options.config)
|
||||
except Bridge_ConfigException as exception:
|
||||
print("Could not parse config file: {}".format(exception))
|
||||
print(f"Could not parse config file: {exception}")
|
||||
sys.exit(1)
|
||||
|
||||
# Get config for each client
|
||||
|
@ -347,11 +345,11 @@ def main() -> None:
|
|||
zulip_client.call_on_each_message(zulip_to_matrix(zulip_config, room))
|
||||
|
||||
except Bridge_FatalMatrixException as exception:
|
||||
sys.exit("Matrix bridge error: {}".format(exception))
|
||||
sys.exit(f"Matrix bridge error: {exception}")
|
||||
except Bridge_ZulipFatalException as exception:
|
||||
sys.exit("Zulip bridge error: {}".format(exception))
|
||||
sys.exit(f"Zulip bridge error: {exception}")
|
||||
except zulip.ZulipError as exception:
|
||||
sys.exit("Zulip error: {}".format(exception))
|
||||
sys.exit(f"Zulip error: {exception}")
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
backoff.fail()
|
||||
|
|
|
@ -49,14 +49,14 @@ class MatrixBridgeScriptTests(TestCase):
|
|||
output_lines = self.output_from_script([])
|
||||
expected_lines = [
|
||||
"Options required: -c or --config to run, OR --write-sample-config.",
|
||||
"usage: {} [-h]".format(script_file),
|
||||
f"usage: {script_file} [-h]",
|
||||
]
|
||||
for expected, output in zip(expected_lines, output_lines):
|
||||
self.assertIn(expected, output)
|
||||
|
||||
def test_help_usage_and_description(self) -> None:
|
||||
output_lines = self.output_from_script(["-h"])
|
||||
usage = "usage: {} [-h]".format(script_file)
|
||||
usage = f"usage: {script_file} [-h]"
|
||||
description = "Script to bridge"
|
||||
self.assertIn(usage, output_lines[0])
|
||||
blank_lines = [num for num, line in enumerate(output_lines) if line == ""]
|
||||
|
@ -71,7 +71,7 @@ class MatrixBridgeScriptTests(TestCase):
|
|||
with new_temp_dir() as tempdir:
|
||||
path = os.path.join(tempdir, sample_config_path)
|
||||
output_lines = self.output_from_script(["--write-sample-config", path])
|
||||
self.assertEqual(output_lines, ["Wrote sample configuration to '{}'".format(path)])
|
||||
self.assertEqual(output_lines, [f"Wrote sample configuration to '{path}'"])
|
||||
|
||||
with open(path) as sample_file:
|
||||
self.assertEqual(sample_file.read(), sample_config_text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue