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

Commit 95e47b2

Browse files
[pyupgrade] synapse/ (#10348)
This PR is tantamount to running ``` pyupgrade --py36-plus --keep-percent-format `find synapse/ -type f -name "*.py"` ``` Part of #9744
1 parent 7387d6f commit 95e47b2

29 files changed

+86
-102
lines changed

changelog.d/10348.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run `pyupgrade` on the codebase.

synapse/app/generic_worker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,8 @@ def start_listening(self):
395395
elif listener.type == "metrics":
396396
if not self.config.enable_metrics:
397397
logger.warning(
398-
(
399-
"Metrics listener configured, but "
400-
"enable_metrics is not True!"
401-
)
398+
"Metrics listener configured, but "
399+
"enable_metrics is not True!"
402400
)
403401
else:
404402
_base.listen_metrics(listener.bind_addresses, listener.port)

synapse/app/homeserver.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,8 @@ def start_listening(self):
305305
elif listener.type == "metrics":
306306
if not self.config.enable_metrics:
307307
logger.warning(
308-
(
309-
"Metrics listener configured, but "
310-
"enable_metrics is not True!"
311-
)
308+
"Metrics listener configured, but "
309+
"enable_metrics is not True!"
312310
)
313311
else:
314312
_base.listen_metrics(listener.bind_addresses, listener.port)

synapse/config/appservice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def load_appservices(hostname, config_files):
6464

6565
for config_file in config_files:
6666
try:
67-
with open(config_file, "r") as f:
67+
with open(config_file) as f:
6868
appservice = _load_appservice(hostname, yaml.safe_load(f), config_file)
6969
if appservice.id in seen_ids:
7070
raise ConfigError(

synapse/config/tls.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ def read_config(self, config: dict, config_dir_path: str, **kwargs):
6666
if self.federation_client_minimum_tls_version == "1.3":
6767
if getattr(SSL, "OP_NO_TLSv1_3", None) is None:
6868
raise ConfigError(
69-
(
70-
"federation_client_minimum_tls_version cannot be 1.3, "
71-
"your OpenSSL does not support it"
72-
)
69+
"federation_client_minimum_tls_version cannot be 1.3, "
70+
"your OpenSSL does not support it"
7371
)
7472

7573
# Whitelist of domains to not verify certificates for

synapse/handlers/cas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, error, error_description=None):
4040

4141
def __str__(self):
4242
if self.error_description:
43-
return "{}: {}".format(self.error, self.error_description)
43+
return f"{self.error}: {self.error_description}"
4444
return self.error
4545

4646

synapse/handlers/federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ async def _get_state_after_missing_prev_event(
735735
# we need to make sure we re-load from the database to get the rejected
736736
# state correct.
737737
fetched_events.update(
738-
(await self.store.get_events(missing_desired_events, allow_rejected=True))
738+
await self.store.get_events(missing_desired_events, allow_rejected=True)
739739
)
740740

741741
# check for events which were in the wrong room.

synapse/handlers/identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async def try_unbind_threepid_with_id_server(
302302
)
303303

304304
url = "https://%s/_matrix/identity/api/v1/3pid/unbind" % (id_server,)
305-
url_bytes = "/_matrix/identity/api/v1/3pid/unbind".encode("ascii")
305+
url_bytes = b"/_matrix/identity/api/v1/3pid/unbind"
306306

307307
content = {
308308
"mxid": mxid,
@@ -695,7 +695,7 @@ async def _lookup_3pid_v1(
695695
return data["mxid"]
696696
except RequestTimedOutError:
697697
raise SynapseError(500, "Timed out contacting identity server")
698-
except IOError as e:
698+
except OSError as e:
699699
logger.warning("Error from v1 identity server lookup: %s" % (e,))
700700

701701
return None

synapse/handlers/oidc.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,26 @@
7272
(b"oidc_session_no_samesite", b"HttpOnly"),
7373
]
7474

75+
7576
#: A token exchanged from the token endpoint, as per RFC6749 sec 5.1. and
7677
#: OpenID.Core sec 3.1.3.3.
77-
Token = TypedDict(
78-
"Token",
79-
{
80-
"access_token": str,
81-
"token_type": str,
82-
"id_token": Optional[str],
83-
"refresh_token": Optional[str],
84-
"expires_in": int,
85-
"scope": Optional[str],
86-
},
87-
)
78+
class Token(TypedDict):
79+
access_token: str
80+
token_type: str
81+
id_token: Optional[str]
82+
refresh_token: Optional[str]
83+
expires_in: int
84+
scope: Optional[str]
85+
8886

8987
#: A JWK, as per RFC7517 sec 4. The type could be more precise than that, but
9088
#: there is no real point of doing this in our case.
9189
JWK = Dict[str, str]
9290

91+
9392
#: A JWK Set, as per RFC7517 sec 5.
94-
JWKS = TypedDict("JWKS", {"keys": List[JWK]})
93+
class JWKS(TypedDict):
94+
keys: List[JWK]
9595

9696

9797
class OidcHandler:
@@ -255,7 +255,7 @@ def __init__(self, error, error_description=None):
255255

256256
def __str__(self):
257257
if self.error_description:
258-
return "{}: {}".format(self.error, self.error_description)
258+
return f"{self.error}: {self.error_description}"
259259
return self.error
260260

261261

@@ -639,7 +639,7 @@ async def _exchange_code(self, code: str) -> Token:
639639
)
640640
logger.warning(description)
641641
# Body was still valid JSON. Might be useful to log it for debugging.
642-
logger.warning("Code exchange response: {resp!r}".format(resp=resp))
642+
logger.warning("Code exchange response: %r", resp)
643643
raise OidcError("server_error", description)
644644

645645
return resp
@@ -1217,10 +1217,12 @@ class OidcSessionData:
12171217
ui_auth_session_id = attr.ib(type=str)
12181218

12191219

1220-
UserAttributeDict = TypedDict(
1221-
"UserAttributeDict",
1222-
{"localpart": Optional[str], "display_name": Optional[str], "emails": List[str]},
1223-
)
1220+
class UserAttributeDict(TypedDict):
1221+
localpart: Optional[str]
1222+
display_name: Optional[str]
1223+
emails: List[str]
1224+
1225+
12241226
C = TypeVar("C")
12251227

12261228

synapse/handlers/register.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,12 @@
5555
["guest", "auth_provider"],
5656
)
5757

58-
LoginDict = TypedDict(
59-
"LoginDict",
60-
{
61-
"device_id": str,
62-
"access_token": str,
63-
"valid_until_ms": Optional[int],
64-
"refresh_token": Optional[str],
65-
},
66-
)
58+
59+
class LoginDict(TypedDict):
60+
device_id: str
61+
access_token: str
62+
valid_until_ms: Optional[int]
63+
refresh_token: Optional[str]
6764

6865

6966
class RegistrationHandler(BaseHandler):

0 commit comments

Comments
 (0)