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

Commit 1a1da60

Browse files
authored
Fix new flake8 errors (#7470)
1 parent 8c8858e commit 1a1da60

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
@@ -19,6 +19,7 @@
1919
import time
2020
from email.mime.multipart import MIMEMultipart
2121
from email.mime.text import MIMEText
22+
from typing import Iterable, List, TypeVar
2223

2324
from six.moves import urllib
2425

@@ -41,6 +42,8 @@
4142

4243
logger = logging.getLogger(__name__)
4344

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

4548
MESSAGE_FROM_PERSON_IN_ROOM = (
4649
"You have a message on %(app)s from %(person)s in the %(room)s room..."
@@ -638,10 +641,10 @@ def safe_text(raw_text):
638641
)
639642

640643

641-
def deduped_ordered_list(l):
644+
def deduped_ordered_list(it: Iterable[T]) -> List[T]:
642645
seen = set()
643646
ret = []
644-
for item in l:
647+
for item in it:
645648
if item not in seen:
646649
seen.add(item)
647650
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)