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

Commit 0a00b7f

Browse files
Update black, and run auto formatting over the codebase (#9381)
- Update black version to the latest - Run black auto formatting over the codebase - Run autoformatting according to [`docs/code_style.md `](https://github.com/matrix-org/synapse/blob/80d6dc9783aa80886a133756028984dbf8920168/docs/code_style.md) - Update `code_style.md` docs around installing black to use the correct version
1 parent 5636e59 commit 0a00b7f

File tree

271 files changed

+2802
-1713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+2802
-1713
lines changed

changelog.d/9381.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update the version of black used to 20.8b1.

contrib/cmdclient/console.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _domain(self):
9292
return self.config["user"].split(":")[1]
9393

9494
def do_config(self, line):
95-
""" Show the config for this client: "config"
95+
"""Show the config for this client: "config"
9696
Edit a key value mapping: "config key value" e.g. "config token 1234"
9797
Config variables:
9898
user: The username to auth with.
@@ -360,7 +360,7 @@ def do_joinalias(self, line):
360360
print(e)
361361

362362
def do_topic(self, line):
363-
""""topic [set|get] <roomid> [<newtopic>]"
363+
""" "topic [set|get] <roomid> [<newtopic>]"
364364
Set the topic for a room: topic set <roomid> <newtopic>
365365
Get the topic for a room: topic get <roomid>
366366
"""
@@ -690,7 +690,7 @@ def do_online(self, line):
690690
self._do_presence_state(2, line)
691691

692692
def _parse(self, line, keys, force_keys=False):
693-
""" Parses the given line.
693+
"""Parses the given line.
694694
695695
Args:
696696
line : The line to parse
@@ -721,7 +721,7 @@ def _run_and_pprint(
721721
query_params={"access_token": None},
722722
alt_text=None,
723723
):
724-
""" Runs an HTTP request and pretty prints the output.
724+
"""Runs an HTTP request and pretty prints the output.
725725
726726
Args:
727727
method: HTTP method

contrib/cmdclient/http.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323

2424

2525
class HttpClient:
26-
""" Interface for talking json over http
27-
"""
26+
"""Interface for talking json over http"""
2827

2928
def put_json(self, url, data):
30-
""" Sends the specifed json data using PUT
29+
"""Sends the specifed json data using PUT
3130
3231
Args:
3332
url (str): The URL to PUT data to.
@@ -41,7 +40,7 @@ def put_json(self, url, data):
4140
pass
4241

4342
def get_json(self, url, args=None):
44-
""" Gets some json from the given host homeserver and path
43+
"""Gets some json from the given host homeserver and path
4544
4645
Args:
4746
url (str): The URL to GET data from.
@@ -58,7 +57,7 @@ def get_json(self, url, args=None):
5857

5958

6059
class TwistedHttpClient(HttpClient):
61-
""" Wrapper around the twisted HTTP client api.
60+
"""Wrapper around the twisted HTTP client api.
6261
6362
Attributes:
6463
agent (twisted.web.client.Agent): The twisted Agent used to send the
@@ -87,8 +86,7 @@ def get_json(self, url, args=None):
8786
defer.returnValue(json.loads(body))
8887

8988
def _create_put_request(self, url, json_data, headers_dict={}):
90-
""" Wrapper of _create_request to issue a PUT request
91-
"""
89+
"""Wrapper of _create_request to issue a PUT request"""
9290

9391
if "Content-Type" not in headers_dict:
9492
raise defer.error(RuntimeError("Must include Content-Type header for PUTs"))
@@ -98,8 +96,7 @@ def _create_put_request(self, url, json_data, headers_dict={}):
9896
)
9997

10098
def _create_get_request(self, url, headers_dict={}):
101-
""" Wrapper of _create_request to issue a GET request
102-
"""
99+
"""Wrapper of _create_request to issue a GET request"""
103100
return self._create_request("GET", url, headers_dict=headers_dict)
104101

105102
@defer.inlineCallbacks
@@ -127,8 +124,7 @@ def do_request(
127124

128125
@defer.inlineCallbacks
129126
def _create_request(self, method, url, producer=None, headers_dict={}):
130-
""" Creates and sends a request to the given url
131-
"""
127+
"""Creates and sends a request to the given url"""
132128
headers_dict["User-Agent"] = ["Synapse Cmd Client"]
133129

134130
retries_left = 5
@@ -185,8 +181,7 @@ def stopProducing(self):
185181

186182

187183
class _JsonProducer:
188-
""" Used by the twisted http client to create the HTTP body from json
189-
"""
184+
"""Used by the twisted http client to create the HTTP body from json"""
190185

191186
def __init__(self, jsn):
192187
self.data = jsn

contrib/experiments/cursesio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def print_log(self, text):
6363
self.redraw()
6464

6565
def redraw(self):
66-
""" method for redisplaying lines
67-
based on internal list of lines """
66+
"""method for redisplaying lines based on internal list of lines"""
6867

6968
self.stdscr.clear()
7069
self.paintStatus(self.statusText)

contrib/experiments/test_messaging.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def excpetion_errback(failure):
5656

5757

5858
class InputOutput:
59-
""" This is responsible for basic I/O so that a user can interact with
59+
"""This is responsible for basic I/O so that a user can interact with
6060
the example app.
6161
"""
6262

@@ -68,8 +68,7 @@ def set_home_server(self, server):
6868
self.server = server
6969

7070
def on_line(self, line):
71-
""" This is where we process commands.
72-
"""
71+
"""This is where we process commands."""
7372

7473
try:
7574
m = re.match(r"^join (\S+)$", line)
@@ -133,7 +132,7 @@ def emit(self, record):
133132

134133

135134
class Room:
136-
""" Used to store (in memory) the current membership state of a room, and
135+
"""Used to store (in memory) the current membership state of a room, and
137136
which home servers we should send PDUs associated with the room to.
138137
"""
139138

@@ -148,8 +147,7 @@ def __init__(self, room_name):
148147
self.have_got_metadata = False
149148

150149
def add_participant(self, participant):
151-
""" Someone has joined the room
152-
"""
150+
"""Someone has joined the room"""
153151
self.participants.add(participant)
154152
self.invited.discard(participant)
155153

@@ -160,14 +158,13 @@ def add_participant(self, participant):
160158
self.oldest_server = server
161159

162160
def add_invited(self, invitee):
163-
""" Someone has been invited to the room
164-
"""
161+
"""Someone has been invited to the room"""
165162
self.invited.add(invitee)
166163
self.servers.add(origin_from_ucid(invitee))
167164

168165

169166
class HomeServer(ReplicationHandler):
170-
""" A very basic home server implentation that allows people to join a
167+
"""A very basic home server implentation that allows people to join a
171168
room and then invite other people.
172169
"""
173170

@@ -181,8 +178,7 @@ def __init__(self, server_name, replication_layer, output):
181178
self.output = output
182179

183180
def on_receive_pdu(self, pdu):
184-
""" We just received a PDU
185-
"""
181+
"""We just received a PDU"""
186182
pdu_type = pdu.pdu_type
187183

188184
if pdu_type == "sy.room.message":
@@ -199,23 +195,20 @@ def on_receive_pdu(self, pdu):
199195
)
200196

201197
def _on_message(self, pdu):
202-
""" We received a message
203-
"""
198+
"""We received a message"""
204199
self.output.print_line(
205200
"#%s %s %s" % (pdu.context, pdu.content["sender"], pdu.content["body"])
206201
)
207202

208203
def _on_join(self, context, joinee):
209-
""" Someone has joined a room, either a remote user or a local user
210-
"""
204+
"""Someone has joined a room, either a remote user or a local user"""
211205
room = self._get_or_create_room(context)
212206
room.add_participant(joinee)
213207

214208
self.output.print_line("#%s %s %s" % (context, joinee, "*** JOINED"))
215209

216210
def _on_invite(self, origin, context, invitee):
217-
""" Someone has been invited
218-
"""
211+
"""Someone has been invited"""
219212
room = self._get_or_create_room(context)
220213
room.add_invited(invitee)
221214

@@ -228,8 +221,7 @@ def _on_invite(self, origin, context, invitee):
228221

229222
@defer.inlineCallbacks
230223
def send_message(self, room_name, sender, body):
231-
""" Send a message to a room!
232-
"""
224+
"""Send a message to a room!"""
233225
destinations = yield self.get_servers_for_context(room_name)
234226

235227
try:
@@ -247,8 +239,7 @@ def send_message(self, room_name, sender, body):
247239

248240
@defer.inlineCallbacks
249241
def join_room(self, room_name, sender, joinee):
250-
""" Join a room!
251-
"""
242+
"""Join a room!"""
252243
self._on_join(room_name, joinee)
253244

254245
destinations = yield self.get_servers_for_context(room_name)
@@ -269,8 +260,7 @@ def join_room(self, room_name, sender, joinee):
269260

270261
@defer.inlineCallbacks
271262
def invite_to_room(self, room_name, sender, invitee):
272-
""" Invite someone to a room!
273-
"""
263+
"""Invite someone to a room!"""
274264
self._on_invite(self.server_name, room_name, invitee)
275265

276266
destinations = yield self.get_servers_for_context(room_name)

contrib/jitsimeetbridge/jitsimeetbridge.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,12 @@ def advertiseSsrcs(self):
193193
time.sleep(7)
194194
print("SSRC spammer started")
195195
while self.running:
196-
ssrcMsg = (
197-
"<presence to='%(tojid)s' xmlns='jabber:client'><x xmlns='http://jabber.org/protocol/muc'/><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://jitsi.org/jitsimeet' ver='0WkSdhFnAUxrz4ImQQLdB80GFlE='/><nick xmlns='http://jabber.org/protocol/nick'>%(nick)s</nick><stats xmlns='http://jitsi.org/jitmeet/stats'><stat name='bitrate_download' value='175'/><stat name='bitrate_upload' value='176'/><stat name='packetLoss_total' value='0'/><stat name='packetLoss_download' value='0'/><stat name='packetLoss_upload' value='0'/></stats><media xmlns='http://estos.de/ns/mjs'><source type='audio' ssrc='%(assrc)s' direction='sendre'/><source type='video' ssrc='%(vssrc)s' direction='sendre'/></media></presence>"
198-
% {
199-
"tojid": "%s@%s/%s" % (ROOMNAME, ROOMDOMAIN, self.shortJid),
200-
"nick": self.userId,
201-
"assrc": self.ssrcs["audio"],
202-
"vssrc": self.ssrcs["video"],
203-
}
204-
)
196+
ssrcMsg = "<presence to='%(tojid)s' xmlns='jabber:client'><x xmlns='http://jabber.org/protocol/muc'/><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://jitsi.org/jitsimeet' ver='0WkSdhFnAUxrz4ImQQLdB80GFlE='/><nick xmlns='http://jabber.org/protocol/nick'>%(nick)s</nick><stats xmlns='http://jitsi.org/jitmeet/stats'><stat name='bitrate_download' value='175'/><stat name='bitrate_upload' value='176'/><stat name='packetLoss_total' value='0'/><stat name='packetLoss_download' value='0'/><stat name='packetLoss_upload' value='0'/></stats><media xmlns='http://estos.de/ns/mjs'><source type='audio' ssrc='%(assrc)s' direction='sendre'/><source type='video' ssrc='%(vssrc)s' direction='sendre'/></media></presence>" % {
197+
"tojid": "%s@%s/%s" % (ROOMNAME, ROOMDOMAIN, self.shortJid),
198+
"nick": self.userId,
199+
"assrc": self.ssrcs["audio"],
200+
"vssrc": self.ssrcs["video"],
201+
}
205202
res = self.sendIq(ssrcMsg)
206203
print("reply from ssrc announce: ", res)
207204
time.sleep(10)

docs/code_style.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ errors in code.
88

99
The necessary tools are detailed below.
1010

11+
First install them with:
12+
13+
pip install -e ".[lint,mypy]"
14+
1115
- **black**
1216

1317
The Synapse codebase uses [black](https://pypi.org/project/black/)
1418
as an opinionated code formatter, ensuring all comitted code is
1519
properly formatted.
1620

17-
First install `black` with:
18-
19-
pip install --upgrade black
20-
2121
Have `black` auto-format your code (it shouldn't change any
2222
functionality) with:
2323

@@ -28,10 +28,6 @@ The necessary tools are detailed below.
2828
`flake8` is a code checking tool. We require code to pass `flake8`
2929
before being merged into the codebase.
3030

31-
Install `flake8` with:
32-
33-
pip install --upgrade flake8 flake8-comprehensions
34-
3531
Check all application and test code with:
3632

3733
flake8 synapse tests
@@ -41,10 +37,6 @@ The necessary tools are detailed below.
4137
`isort` ensures imports are nicely formatted, and can suggest and
4238
auto-fix issues such as double-importing.
4339

44-
Install `isort` with:
45-
46-
pip install --upgrade isort
47-
4840
Auto-fix imports with:
4941

5042
isort -rc synapse tests

scripts-dev/mypy_synapse_plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def cached_function_method_signature(ctx: MethodSigContext) -> CallableType:
8787
arg_kinds.append(ARG_NAMED_OPT) # Arg is an optional kwarg.
8888

8989
signature = signature.copy_modified(
90-
arg_types=arg_types, arg_names=arg_names, arg_kinds=arg_kinds,
90+
arg_types=arg_types,
91+
arg_names=arg_names,
92+
arg_kinds=arg_kinds,
9193
)
9294

9395
return signature

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def exec_file(path_segments):
9797
# We pin black so that our tests don't start failing on new releases.
9898
CONDITIONAL_REQUIREMENTS["lint"] = [
9999
"isort==5.7.0",
100-
"black==19.10b0",
100+
"black==20.8b1",
101101
"flake8-comprehensions",
102102
"flake8",
103103
]

stubs/sortedcontainers/sorteddict.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ class SortedDict(Dict[_KT, _VT]):
8989
def __reduce__(
9090
self,
9191
) -> Tuple[
92-
Type[SortedDict[_KT, _VT]], Tuple[Callable[[_KT], Any], List[Tuple[_KT, _VT]]],
92+
Type[SortedDict[_KT, _VT]],
93+
Tuple[Callable[[_KT], Any], List[Tuple[_KT, _VT]]],
9394
]: ...
9495
def __repr__(self) -> str: ...
9596
def _check(self) -> None: ...
9697
def islice(
97-
self, start: Optional[int] = ..., stop: Optional[int] = ..., reverse=bool,
98+
self,
99+
start: Optional[int] = ...,
100+
stop: Optional[int] = ...,
101+
reverse=bool,
98102
) -> Iterator[_KT]: ...
99103
def bisect_left(self, value: _KT) -> int: ...
100104
def bisect_right(self, value: _KT) -> int: ...

0 commit comments

Comments
 (0)