ruff: Fix SIM105 Use contextlib.suppress instead of try-except-pass.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-29 17:09:50 -07:00
parent 6a4ad8861b
commit 2aa36f90fb
2 changed files with 7 additions and 11 deletions

View file

@ -121,15 +121,13 @@ class JabberToZulipBot(ClientXMPP):
# Configure the room. Really, we should only do this if the room is # Configure the room. Really, we should only do this if the room is
# newly created. # newly created.
form = None
try: try:
form = xep0045.getRoomConfig(muc_jid) form = xep0045.getRoomConfig(muc_jid)
except ValueError: except ValueError:
pass
if form:
xep0045.configureRoom(muc_jid, form)
else:
logging.error("Could not configure room: %s", muc_jid) logging.error("Could not configure room: %s", muc_jid)
return
xep0045.configureRoom(muc_jid, form)
def leave_muc(self, room: str) -> None: def leave_muc(self, room: str) -> None:
if room not in self.rooms: if room not in self.rooms:

View file

@ -1,7 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import contextlib
import errno import errno
import json
import os import os
import platform import platform
import re import re
@ -9,6 +11,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import traceback import traceback
from typing import List
# Use the Zulip virtualenv if available # Use the Zulip virtualenv if available
sys.path.append("/home/zulip/deployments/current") sys.path.append("/home/zulip/deployments/current")
@ -24,10 +27,7 @@ except ImportError:
except ImportError: except ImportError:
pass pass
import json
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../")) sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../"))
from typing import List
import zulip import zulip
@ -129,7 +129,5 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
process_logs() process_logs()
finally: finally:
try: with contextlib.suppress(OSError):
os.remove(lock_path) os.remove(lock_path)
except OSError:
pass