Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit aa483cb

Browse files
authored
Update ruff config (#16283)
Enable additional checks & clean-up unneeded configuration.
1 parent c1c6c95 commit aa483cb

26 files changed

+63
-64
lines changed

changelog.d/16283.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enable additional linting checks.

contrib/cmdclient/http.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def put_json(self, url, data):
3737
Deferred: Succeeds when we get a 2xx HTTP response. The result
3838
will be the decoded JSON body.
3939
"""
40-
pass
4140

4241
def get_json(self, url, args=None):
4342
"""Gets some json from the given host homeserver and path
@@ -53,7 +52,6 @@ def get_json(self, url, args=None):
5352
Deferred: Succeeds when we get a 2xx HTTP response. The result
5453
will be the decoded JSON body.
5554
"""
56-
pass
5755

5856

5957
class TwistedHttpClient(HttpClient):

docker/start.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def main(args: List[str], environ: MutableMapping[str, str]) -> None:
239239
log("Could not find %s, will not use" % (jemallocpath,))
240240

241241
# if there are no config files passed to synapse, try adding the default file
242-
if not any(p.startswith("--config-path") or p.startswith("-c") for p in args):
242+
if not any(p.startswith(("--config-path", "-c")) for p in args):
243243
config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data")
244244
config_path = environ.get(
245245
"SYNAPSE_CONFIG_PATH", config_dir + "/homeserver.yaml"

pyproject.toml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,39 @@ target-version = ['py38', 'py39', 'py310', 'py311']
4343
[tool.ruff]
4444
line-length = 88
4545

46-
# See https://github.com/charliermarsh/ruff/#pycodestyle
46+
# See https://beta.ruff.rs/docs/rules/#error-e
4747
# for error codes. The ones we ignore are:
48-
# E731: do not assign a lambda expression, use a def
4948
# E501: Line too long (black enforces this for us)
49+
# E731: do not assign a lambda expression, use a def
5050
#
5151
# flake8-bugbear compatible checks. Its error codes are described at
52-
# https://github.com/charliermarsh/ruff/#flake8-bugbear
53-
# B019: Use of functools.lru_cache or functools.cache on methods can lead to memory leaks
52+
# https://beta.ruff.rs/docs/rules/#flake8-bugbear-b
5453
# B023: Functions defined inside a loop must not use variables redefined in the loop
55-
# B024: Abstract base class with no abstract method.
5654
ignore = [
57-
"B019",
5855
"B023",
59-
"B024",
6056
"E501",
6157
"E731",
6258
]
6359
select = [
64-
# pycodestyle checks.
60+
# pycodestyle
6561
"E",
6662
"W",
67-
# pyflakes checks.
63+
# pyflakes
6864
"F",
69-
# flake8-bugbear checks.
65+
# flake8-bugbear
7066
"B0",
71-
# flake8-comprehensions checks.
67+
# flake8-comprehensions
7268
"C4",
69+
# flake8-2020
70+
"YTT",
71+
# flake8-slots
72+
"SLOT",
73+
# flake8-debugger
74+
"T10",
75+
# flake8-pie
76+
"PIE",
77+
# flake8-executable
78+
"EXE",
7379
]
7480

7581
[tool.isort]

scripts-dev/mypy_synapse_plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def get_method_signature_hook(
3030
self, fullname: str
3131
) -> Optional[Callable[[MethodSigContext], CallableType]]:
3232
if fullname.startswith(
33-
"synapse.util.caches.descriptors.CachedFunction.__call__"
34-
) or fullname.startswith(
35-
"synapse.util.caches.descriptors._LruCachedFunction.__call__"
33+
(
34+
"synapse.util.caches.descriptors.CachedFunction.__call__",
35+
"synapse.util.caches.descriptors._LruCachedFunction.__call__",
36+
)
3637
):
3738
return cached_function_method_signature
3839
return None

synapse/_scripts/update_synapse_database.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright 2019 The Matrix.org Foundation C.I.C.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

synapse/events/snapshot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ async def persist(
5555
A method to convert an UnpersistedEventContext to an EventContext, suitable for
5656
sending to the database with the associated event.
5757
"""
58-
pass
5958

6059
@abstractmethod
6160
async def get_prev_state_ids(
@@ -69,7 +68,6 @@ async def get_prev_state_ids(
6968
state_filter: specifies the type of state event to fetch from DB, example:
7069
EventTypes.JoinRules
7170
"""
72-
pass
7371

7472

7573
@attr.s(slots=True, auto_attribs=True)

synapse/media/url_previewer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,7 @@ def _is_media(content_type: str) -> bool:
846846

847847
def _is_html(content_type: str) -> bool:
848848
content_type = content_type.lower()
849-
return content_type.startswith("text/html") or content_type.startswith(
850-
"application/xhtml"
851-
)
849+
return content_type.startswith(("text/html", "application/xhtml"))
852850

853851

854852
def _is_json(content_type: str) -> bool:

synapse/storage/background_updates.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ class Constraint(metaclass=abc.ABCMeta):
6262
@abc.abstractmethod
6363
def make_check_clause(self, table: str) -> str:
6464
"""Returns an SQL expression that checks the row passes the constraint."""
65-
pass
6665

6766
@abc.abstractmethod
6867
def make_constraint_clause_postgres(self) -> str:
6968
"""Returns an SQL clause for creating the constraint.
7069
7170
Only used on Postgres DBs
7271
"""
73-
pass
7472

7573

7674
@attr.s(auto_attribs=True)

synmark/suites/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Config:
112112
start = perf_counter()
113113

114114
# Send a bunch of useful messages
115-
for i in range(0, loops):
115+
for i in range(loops):
116116
logger.info("test message %s", i)
117117

118118
if len(handler._buffer) == handler.maximum_buffer:

tests/handlers/test_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_delete_device_and_big_device_inbox(self) -> None:
223223

224224
# queue a bunch of messages in the inbox
225225
requester = create_requester(sender, device_id=DEVICE_ID)
226-
for i in range(0, DeviceHandler.DEVICE_MSGS_DELETE_BATCH_LIMIT + 10):
226+
for i in range(DeviceHandler.DEVICE_MSGS_DELETE_BATCH_LIMIT + 10):
227227
self.get_success(
228228
self.device_message_handler.send_device_message(
229229
requester, "message_type", {receiver: {"*": {"val": i}}}

tests/handlers/test_federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_backfill_with_many_backward_extremities(self) -> None:
262262
if (ev.type, ev.state_key)
263263
in {("m.room.create", ""), ("m.room.member", remote_server_user_id)}
264264
]
265-
for _ in range(0, 8):
265+
for _ in range(8):
266266
event = make_event_from_dict(
267267
self.add_hashes_and_signatures_from_other_server(
268268
{

tests/logging/test_remote_handler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def test_log_backpressure_debug(self) -> None:
7878
logger = self.get_logger(handler)
7979

8080
# Send some debug messages
81-
for i in range(0, 3):
81+
for i in range(3):
8282
logger.debug("debug %s" % (i,))
8383

8484
# Send a bunch of useful messages
85-
for i in range(0, 7):
85+
for i in range(7):
8686
logger.info("info %s" % (i,))
8787

8888
# The last debug message pushes it past the maximum buffer
@@ -108,15 +108,15 @@ def test_log_backpressure_info(self) -> None:
108108
logger = self.get_logger(handler)
109109

110110
# Send some debug messages
111-
for i in range(0, 3):
111+
for i in range(3):
112112
logger.debug("debug %s" % (i,))
113113

114114
# Send a bunch of useful messages
115-
for i in range(0, 10):
115+
for i in range(10):
116116
logger.warning("warn %s" % (i,))
117117

118118
# Send a bunch of info messages
119-
for i in range(0, 3):
119+
for i in range(3):
120120
logger.info("info %s" % (i,))
121121

122122
# The last debug message pushes it past the maximum buffer
@@ -144,7 +144,7 @@ def test_log_backpressure_cut_middle(self) -> None:
144144
logger = self.get_logger(handler)
145145

146146
# Send a bunch of useful messages
147-
for i in range(0, 20):
147+
for i in range(20):
148148
logger.warning("warn %s" % (i,))
149149

150150
# Allow the reconnection

tests/replication/tcp/streams/test_to_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_to_device_stream(self) -> None:
4949

5050
# add messages to the device inbox for user1 up until the
5151
# limit defined for a stream update batch
52-
for i in range(0, _STREAM_UPDATE_TARGET_ROW_COUNT):
52+
for i in range(_STREAM_UPDATE_TARGET_ROW_COUNT):
5353
msg["content"] = {"device": {}}
5454
messages = {user1: {"device": msg}}
5555

tests/rest/admin/test_federation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def _create_destinations(self, number_destinations: int) -> None:
510510
Args:
511511
number_destinations: Number of destinations to be created
512512
"""
513-
for i in range(0, number_destinations):
513+
for i in range(number_destinations):
514514
dest = f"sub{i}.example.com"
515515
self._create_destination(dest, 50, 50, 50, 100)
516516

@@ -690,7 +690,7 @@ def test_order_direction(self) -> None:
690690
self._check_fields(channel_desc.json_body["rooms"])
691691

692692
# test that both lists have different directions
693-
for i in range(0, number_rooms):
693+
for i in range(number_rooms):
694694
self.assertEqual(
695695
channel_asc.json_body["rooms"][i]["room_id"],
696696
channel_desc.json_body["rooms"][number_rooms - 1 - i]["room_id"],
@@ -777,7 +777,7 @@ def _create_destination_rooms(self, number_rooms: int) -> None:
777777
Args:
778778
number_rooms: Number of rooms to be created
779779
"""
780-
for _ in range(0, number_rooms):
780+
for _ in range(number_rooms):
781781
room_id = self.helper.create_room_as(
782782
self.admin_user, tok=self.admin_user_tok
783783
)

tests/rest/client/test_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def test_background_update_deletes_deactivated_users_server_side_backup_keys(
575575

576576
# create a bunch of users and add keys for them
577577
users = []
578-
for i in range(0, 20):
578+
for i in range(20):
579579
user_id = self.register_user("missPiggy" + str(i), "test")
580580
users.append((user_id,))
581581

tests/rest/client/test_login.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
176176
def test_POST_ratelimiting_per_address(self) -> None:
177177
# Create different users so we're sure not to be bothered by the per-user
178178
# ratelimiter.
179-
for i in range(0, 6):
179+
for i in range(6):
180180
self.register_user("kermit" + str(i), "monkey")
181181

182-
for i in range(0, 6):
182+
for i in range(6):
183183
params = {
184184
"type": "m.login.password",
185185
"identifier": {"type": "m.id.user", "user": "kermit" + str(i)},
@@ -228,7 +228,7 @@ def test_POST_ratelimiting_per_address(self) -> None:
228228
def test_POST_ratelimiting_per_account(self) -> None:
229229
self.register_user("kermit", "monkey")
230230

231-
for i in range(0, 6):
231+
for i in range(6):
232232
params = {
233233
"type": "m.login.password",
234234
"identifier": {"type": "m.id.user", "user": "kermit"},
@@ -277,7 +277,7 @@ def test_POST_ratelimiting_per_account(self) -> None:
277277
def test_POST_ratelimiting_per_account_failed_attempts(self) -> None:
278278
self.register_user("kermit", "monkey")
279279

280-
for i in range(0, 6):
280+
for i in range(6):
281281
params = {
282282
"type": "m.login.password",
283283
"identifier": {"type": "m.id.user", "user": "kermit"},

tests/rest/client/test_register.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_POST_disabled_guest_registration(self) -> None:
169169

170170
@override_config({"rc_registration": {"per_second": 0.17, "burst_count": 5}})
171171
def test_POST_ratelimiting_guest(self) -> None:
172-
for i in range(0, 6):
172+
for i in range(6):
173173
url = self.url + b"?kind=guest"
174174
channel = self.make_request(b"POST", url, b"{}")
175175

@@ -187,7 +187,7 @@ def test_POST_ratelimiting_guest(self) -> None:
187187

188188
@override_config({"rc_registration": {"per_second": 0.17, "burst_count": 5}})
189189
def test_POST_ratelimiting(self) -> None:
190-
for i in range(0, 6):
190+
for i in range(6):
191191
request_data = {
192192
"username": "kermit" + str(i),
193193
"password": "monkey",
@@ -1223,7 +1223,7 @@ def test_GET_token_invalid(self) -> None:
12231223
def test_GET_ratelimiting(self) -> None:
12241224
token = "1234"
12251225

1226-
for i in range(0, 6):
1226+
for i in range(6):
12271227
channel = self.make_request(
12281228
b"GET",
12291229
f"{self.url}?token={token}",

tests/storage/databases/main/test_lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def test_maintain_lock(self) -> None:
382382
self.get_success(lock.__aenter__())
383383

384384
# Wait for ages with the lock, we should not be able to get the lock.
385-
for _ in range(0, 10):
385+
for _ in range(10):
386386
self.reactor.advance((_RENEWAL_INTERVAL_MS / 1000))
387387

388388
lock2 = self.get_success(

tests/storage/test_event_chain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def test_background_update_single_large_room(self) -> None:
664664

665665
# Add a bunch of state so that it takes multiple iterations of the
666666
# background update to process the room.
667-
for i in range(0, 150):
667+
for i in range(150):
668668
self.helper.send_state(
669669
room_id, event_type="m.test", body={"index": i}, tok=self.token
670670
)
@@ -718,12 +718,12 @@ def test_background_update_multiple_large_room(self) -> None:
718718

719719
# Add a bunch of state so that it takes multiple iterations of the
720720
# background update to process the room.
721-
for i in range(0, 150):
721+
for i in range(150):
722722
self.helper.send_state(
723723
room_id1, event_type="m.test", body={"index": i}, tok=self.token
724724
)
725725

726-
for i in range(0, 150):
726+
for i in range(150):
727727
self.helper.send_state(
728728
room_id2, event_type="m.test", body={"index": i}, tok=self.token
729729
)

tests/storage/test_event_federation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ def insert_event(txn: Cursor, i: int) -> None:
227227
(room_id, event_id),
228228
)
229229

230-
for i in range(0, 20):
230+
for i in range(20):
231231
self.get_success(
232232
self.store.db_pool.runInteraction("insert", insert_event, i)
233233
)
234234

235235
# this should get the last ten
236236
r = self.get_success(self.store.get_prev_events_for_room(room_id))
237237
self.assertEqual(10, len(r))
238-
for i in range(0, 10):
238+
for i in range(10):
239239
self.assertEqual("$event_%i:local" % (19 - i), r[i])
240240

241241
def test_get_rooms_with_many_extremities(self) -> None:
@@ -277,7 +277,7 @@ def insert_event(txn: LoggingTransaction, i: int, room_id: str) -> None:
277277
(room_id, event_id),
278278
)
279279

280-
for i in range(0, 20):
280+
for i in range(20):
281281
self.get_success(
282282
self.store.db_pool.runInteraction("insert", insert_event, i, room1)
283283
)

tests/storage/test_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def f(txn: LoggingTransaction) -> None:
8282

8383
self.get_success(self.store.db_pool.runInteraction("", f))
8484

85-
for i in range(0, 70):
85+
for i in range(70):
8686
self.get_success(
8787
self.store.db_pool.simple_insert(
8888
"profiles",
@@ -115,7 +115,7 @@ def f(txn: LoggingTransaction) -> None:
115115
)
116116

117117
expected_values = []
118-
for i in range(0, 70):
118+
for i in range(70):
119119
expected_values.append((f"@hello{i:02}:{self.hs.hostname}",))
120120

121121
res = self.get_success(

tests/storage/test_txn_limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ def do_select(txn: Cursor) -> None:
3838
db_pool = self.hs.get_datastores().databases[0]
3939

4040
# force txn limit to roll over at least once
41-
for _ in range(0, 1001):
41+
for _ in range(1001):
4242
self.get_success_or_raise(db_pool.runInteraction("test_select", do_select))

0 commit comments

Comments
 (0)