Skip to content

Commit 51bddfa

Browse files
erikjohnstonphil-flex
authored andcommitted
Fix new flake8 errors (matrix-org#7470)
1 parent ac45366 commit 51bddfa

7 files changed

Lines changed: 19 additions & 12 deletions

File tree

changelog.d/7470.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix linting errors in new version of Flake8.

synapse/app/_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import traceback
2323

2424
from daemonize import Daemonize
25+
from typing_extensions import NoReturn
2526

2627
from twisted.internet import defer, error, reactor
2728
from twisted.protocols.tls import TLSMemoryBIOFactory
@@ -139,9 +140,9 @@ def run():
139140
run()
140141

141142

142-
def quit_with_error(error_string):
143+
def quit_with_error(error_string: str) -> NoReturn:
143144
message_lines = error_string.split("\n")
144-
line_length = max(len(l) for l in message_lines if len(l) < 80) + 2
145+
line_length = max(len(line) for line in message_lines if len(line) < 80) + 2
145146
sys.stderr.write("*" * line_length + "\n")
146147
for line in message_lines:
147148
sys.stderr.write(" %s\n" % (line.rstrip(),))

synapse/config/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class LimitRemoteRoomsConfig(object):
522522
)
523523

524524
def has_tls_listener(self) -> bool:
525-
return any(l["tls"] for l in self.listeners)
525+
return any(listener["tls"] for listener in self.listeners)
526526

527527
def generate_config_section(
528528
self, server_name, data_dir_path, open_private_ports, listeners, **kwargs

synapse/notifier.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import logging
1717
from collections import namedtuple
18-
from typing import Callable, List
18+
from typing import Callable, Iterable, List, TypeVar
1919

2020
from prometheus_client import Counter
2121

@@ -42,12 +42,14 @@
4242
"synapse_notifier_users_woken_by_stream", "", ["stream"]
4343
)
4444

45+
T = TypeVar("T")
46+
4547

4648
# TODO(paul): Should be shared somewhere
47-
def count(func, l):
48-
"""Return the number of items in l for which func returns true."""
49+
def count(func: Callable[[T], bool], it: Iterable[T]) -> int:
50+
"""Return the number of items in it for which func returns true."""
4951
n = 0
50-
for x in l:
52+
for x in it:
5153
if func(x):
5254
n += 1
5355
return n

synapse/push/mailer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import urllib
2121
from email.mime.multipart import MIMEMultipart
2222
from email.mime.text import MIMEText
23+
from typing import Iterable, List, TypeVar
2324

2425
import bleach
2526
import jinja2
@@ -40,6 +41,8 @@
4041

4142
logger = logging.getLogger(__name__)
4243

44+
T = TypeVar("T")
45+
4346

4447
MESSAGE_FROM_PERSON_IN_ROOM = "You have a message on %(app)s from %(person)s " \
4548
"in the %(room)s room..."
@@ -500,10 +503,10 @@ def safe_text(raw_text):
500503
)))
501504

502505

503-
def deduped_ordered_list(l):
506+
def deduped_ordered_list(it: Iterable[T]) -> List[T]:
504507
seen = set()
505508
ret = []
506-
for item in l:
509+
for item in it:
507510
if item not in seen:
508511
seen.add(item)
509512
ret.append(item)

synapse/storage/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ def execute(self, sql: str, *args: Any):
214214
def executemany(self, sql: str, *args: Any):
215215
self._do_execute(self.txn.executemany, sql, *args)
216216

217-
def _make_sql_one_line(self, sql):
217+
def _make_sql_one_line(self, sql: str) -> str:
218218
"Strip newlines out of SQL so that the loggers in the DB are on one line"
219-
return " ".join(l.strip() for l in sql.splitlines() if l.strip())
219+
return " ".join(line.strip() for line in sql.splitlines() if line.strip())
220220

221221
def _do_execute(self, func, sql, *args):
222222
sql = self._make_sql_one_line(sql)

tests/config/test_load.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def generate_config_and_remove_lines_containing(self, needle):
122122

123123
with open(self.file, "r") as f:
124124
contents = f.readlines()
125-
contents = [l for l in contents if needle not in l]
125+
contents = [line for line in contents if needle not in line]
126126
with open(self.file, "w") as f:
127127
f.write("".join(contents))
128128

0 commit comments

Comments
 (0)