Skip to content

Commit aeb89bc

Browse files
committed
ruff: Enable lots of rules.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent e942cce commit aeb89bc

File tree

20 files changed

+81
-35
lines changed

20 files changed

+81
-35
lines changed

pyproject.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,60 @@ pythonpath = [
9494

9595
[tool.ruff]
9696
select = [
97+
"B", # bugbear
98+
"C4", # comprehensions
99+
"COM", # trailing comma
100+
"DTZ", # naive datetime
97101
"E", # style errors
102+
"EXE", # shebang
98103
"F", # flakes
104+
"FLY", # string formatting
105+
"G", # logging format
99106
"I", # import sorting
107+
"ICN", # import conventions
108+
"INT", # gettext
109+
"ISC", # string concatenation
110+
"N", # naming
111+
"PERF", # performance
112+
"PGH", # pygrep-hooks
113+
"PIE", # miscellaneous
114+
"PL", # pylint
115+
"PYI", # typing stubs
116+
"Q", # quotes
117+
"RSE", # raise
118+
"RUF", # Ruff
119+
"S", # security
120+
"SLF", # self
121+
"SLOT", # slots
122+
"SIM", # simplify
123+
"T10", # debugger
124+
"TID", # tidy imports
125+
"TRY", # try
126+
"UP", # upgrade
127+
"W", # style warnings
128+
"YTT", # sys.version
100129
]
101130
ignore = [
131+
"C408", # Unnecessary `dict` call (rewrite as a literal)
132+
"COM812", # Trailing comma missing
102133
"E402", # Module level import not at top of file
103134
"E501", # Line too long
104135
"E731", # Do not assign a `lambda` expression, use a `def`
136+
"PERF203", # `try`-`except` within a loop incurs performance overhead
137+
"PLR0911", # Too many return statements
138+
"PLR0912", # Too many branches
139+
"PLR0913", # Too many arguments in function definition
140+
"PLR0915", # Too many statements
141+
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
142+
"RUF001", # String contains ambiguous character
143+
"S101", # Use of `assert` detected
144+
"S113", # Probable use of requests call without timeout
145+
"S603", # `subprocess` call: check for execution of untrusted input
146+
"S606", # Starting a process without a shell
147+
"S607", # Starting a process with a partial executable path
148+
"SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements
149+
"TRY003", # Avoid specifying long messages outside the exception class
150+
"TRY400", # Use `logging.exception` instead of `logging.error`
105151
]
106152
src = [
107153
"tools",

tools/deploy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def upload(options: argparse.Namespace) -> None:
112112
if not os.path.exists(file_path):
113113
print(f"upload: Could not find bot package at {file_path}.")
114114
sys.exit(1)
115-
files = {"file": open(file_path, "rb")}
115+
files = {"file": open(file_path, "rb")} # noqa: SIM115
116116
headers = {"key": options.token}
117117
url = urllib.parse.urljoin(options.server, "bots/upload")
118118
response = requests.post(url, files=files, headers=headers)

zulip/integrations/bridge_with_matrix/matrix_bridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ async def handle_media(self, msg: str) -> Tuple[Optional[List[Dict[str, Any]]],
353353
continue
354354

355355
try:
356-
with urllib.request.urlopen(self.server_url + result["url"]) as response:
356+
with urllib.request.urlopen(self.server_url + result["url"]) as response: # noqa: S310
357357
file_content: bytes = response.read()
358358
mimetype: str = response.headers.get_content_type()
359359
except Exception:

zulip/integrations/google/get-google-credentials

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
1414
SCOPES = "https://www.googleapis.com/auth/calendar.readonly"
1515
# This file contains the information that google uses to figure out which application is requesting
1616
# this client's data.
17-
CLIENT_SECRET_FILE = "client_secret.json"
17+
CLIENT_SECRET_FILE = "client_secret.json" # noqa: S105
1818
APPLICATION_NAME = "Zulip Calendar Bot"
1919
HOME_DIR = os.path.expanduser("~")
2020

zulip/integrations/google/google-calendar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "../../"))
2727
import zulip
2828

2929
SCOPES = "https://www.googleapis.com/auth/calendar.readonly"
30-
CLIENT_SECRET_FILE = "client_secret.json"
30+
CLIENT_SECRET_FILE = "client_secret.json" # noqa: S105
3131
APPLICATION_NAME = "Zulip"
3232
HOME_DIR = os.path.expanduser("~")
3333

zulip/integrations/rss/rss-bot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def strip_tags(html: str) -> str:
156156
def compute_entry_hash(entry: Dict[str, Any]) -> str:
157157
entry_time = entry.get("published", entry.get("updated"))
158158
entry_id = entry.get("id", entry.get("link"))
159-
return hashlib.md5((entry_id + str(entry_time)).encode()).hexdigest()
159+
return hashlib.md5((entry_id + str(entry_time)).encode()).hexdigest() # noqa: S324
160160

161161

162162
def unwrap_text(body: str) -> str:

zulip/integrations/zephyr/check-mirroring

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if options.sharded:
6464
for stream, test in test_streams:
6565
if stream == "message":
6666
continue
67-
assert hashlib.sha1(stream.encode("utf-8")).hexdigest().startswith(test)
67+
assert hashlib.sha1(stream.encode("utf-8")).hexdigest().startswith(test) # noqa: S324
6868
else:
6969
test_streams = [
7070
("message", "p"),

zulip/integrations/zephyr/zephyr_ctypes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# --- glibc/sysdeps/unix/sysv/linux/bits/socket.h ---
3232

3333

34-
class sockaddr(Structure):
34+
class sockaddr(Structure): # noqa: N801
3535
_fields_ = (
3636
("sa_family", sa_family_t),
3737
("sa_data", c_char * 14),
@@ -44,11 +44,11 @@ class sockaddr(Structure):
4444
in_addr_t = c_uint32
4545

4646

47-
class in_addr(Structure):
47+
class in_addr(Structure): # noqa: N801
4848
_fields_ = (("s_addr", in_addr_t),)
4949

5050

51-
class sockaddr_in(Structure):
51+
class sockaddr_in(Structure): # noqa: N801
5252
_fields_ = (
5353
("sin_family", sa_family_t),
5454
("sin_port", in_port_t),
@@ -57,11 +57,11 @@ class sockaddr_in(Structure):
5757
)
5858

5959

60-
class in6_addr(Structure):
60+
class in6_addr(Structure): # noqa: N801
6161
_fields_ = (("s6_addr", c_uint8 * 16),)
6262

6363

64-
class sockaddr_in6(Structure):
64+
class sockaddr_in6(Structure): # noqa: N801
6565
_fields_ = (
6666
("sin6_family", sa_family_t),
6767
("sin6_port", in_port_t),
@@ -95,7 +95,7 @@ class _ZTimeval(Structure):
9595
)
9696

9797

98-
class ZUnique_Id_t(Structure):
98+
class ZUnique_Id_t(Structure): # noqa: N801
9999
_fields_ = (
100100
("zuid_addr", in_addr),
101101
("tv", _ZTimeval),
@@ -113,7 +113,7 @@ class _ZSenderSockaddr(Union):
113113
)
114114

115115

116-
class ZNotice_t(Structure):
116+
class ZNotice_t(Structure): # noqa: N801
117117
_fields_ = (
118118
("z_packet", c_char_p),
119119
("z_version", c_char_p),
@@ -146,7 +146,7 @@ class ZNotice_t(Structure):
146146
)
147147

148148

149-
class ZSubscription_t(Structure):
149+
class ZSubscription_t(Structure): # noqa: N801
150150
_fields_ = (
151151
("zsub_recipient", c_char_p),
152152
("zsub_class", c_char_p),

zulip/integrations/zephyr/zephyr_mirror_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def update_subscriptions() -> None:
259259
classes_to_subscribe = set()
260260
for stream in public_streams:
261261
zephyr_class = stream
262-
if options.shard is not None and not hashlib.sha1(
262+
if options.shard is not None and not hashlib.sha1( # noqa: S324
263263
zephyr_class.encode("utf-8")
264264
).hexdigest().startswith(options.shard):
265265
# This stream is being handled by a different zephyr_mirror job.

zulip/zulip/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def fail(self) -> None:
128128
# Exponential growth with ratio sqrt(2); compute random delay
129129
# between x and 2x where x is growing exponentially
130130
delay_scale = int(2 ** (self.number_of_retries / 2.0 - 1)) + 1
131-
delay = min(delay_scale + random.randint(1, delay_scale), self.delay_cap)
131+
delay = min(delay_scale + random.randint(1, delay_scale), self.delay_cap) # noqa: S311
132132
message = f"Sleeping for {delay}s [max {delay_scale * 2}] before retrying."
133133
try:
134134
logger.warning(message)

0 commit comments

Comments
 (0)