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

Commit

Permalink
Fix new flake8 errors (#7470)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored and clokep committed May 13, 2020
1 parent fa4af2c commit df0e061
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.d/7470.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix linting errors in new version of Flake8.
5 changes: 3 additions & 2 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import traceback

from daemonize import Daemonize
from typing_extensions import NoReturn

from twisted.internet import defer, error, reactor
from twisted.protocols.tls import TLSMemoryBIOFactory
Expand Down Expand Up @@ -139,9 +140,9 @@ def run():
run()


def quit_with_error(error_string):
def quit_with_error(error_string: str) -> NoReturn:
message_lines = error_string.split("\n")
line_length = max(len(l) for l in message_lines if len(l) < 80) + 2
line_length = max(len(line) for line in message_lines if len(line) < 80) + 2
sys.stderr.write("*" * line_length + "\n")
for line in message_lines:
sys.stderr.write(" %s\n" % (line.rstrip(),))
Expand Down
2 changes: 1 addition & 1 deletion synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class LimitRemoteRoomsConfig(object):
)

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

def generate_config_section(
self, server_name, data_dir_path, open_private_ports, listeners, **kwargs
Expand Down
10 changes: 6 additions & 4 deletions synapse/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import logging
from collections import namedtuple
from typing import Callable, List
from typing import Callable, Iterable, List, TypeVar

from prometheus_client import Counter

Expand All @@ -42,12 +42,14 @@
"synapse_notifier_users_woken_by_stream", "", ["stream"]
)

T = TypeVar("T")


# TODO(paul): Should be shared somewhere
def count(func, l):
"""Return the number of items in l for which func returns true."""
def count(func: Callable[[T], bool], it: Iterable[T]) -> int:
"""Return the number of items in it for which func returns true."""
n = 0
for x in l:
for x in it:
if func(x):
n += 1
return n
Expand Down
7 changes: 5 additions & 2 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from typing import Iterable, List, TypeVar

from six.moves import urllib

Expand All @@ -41,6 +42,8 @@

logger = logging.getLogger(__name__)

T = TypeVar("T")


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


def deduped_ordered_list(l):
def deduped_ordered_list(it: Iterable[T]) -> List[T]:
seen = set()
ret = []
for item in l:
for item in it:
if item not in seen:
seen.add(item)
ret.append(item)
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ def execute(self, sql: str, *args: Any):
def executemany(self, sql: str, *args: Any):
self._do_execute(self.txn.executemany, sql, *args)

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

def _do_execute(self, func, sql, *args):
sql = self._make_sql_one_line(sql)
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def generate_config_and_remove_lines_containing(self, needle):

with open(self.file, "r") as f:
contents = f.readlines()
contents = [l for l in contents if needle not in l]
contents = [line for line in contents if needle not in line]
with open(self.file, "w") as f:
f.write("".join(contents))

Expand Down

0 comments on commit df0e061

Please sign in to comment.