Skip to content

Commit 5a3ff2a

Browse files
committed
Apply ruff and mypy auto-fixes across codebase
1 parent 313b226 commit 5a3ff2a

Some content is hidden

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

77 files changed

+378
-458
lines changed

integration-tests/matrix_is_tester/base_api_test.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#!/usr/bin/env python
2-
3-
# -*- coding: utf-8 -*-
4-
51
# Copyright 2019 The Matrix.org Foundation C.I.C.
62
#
73
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +22,7 @@
2622
logger = logging.getLogger(__name__)
2723

2824

29-
class BaseApiTest(object):
25+
class BaseApiTest:
3026
"""
3127
Not a test case itself, but can be subclassed to test APIs common
3228
between versions.
@@ -45,7 +41,7 @@ def test_ping(self):
4541

4642
def test_request_email_code(self):
4743
body = self.api.request_email_code("fakeemail1@nowhere.test", "sekrit", 1)
48-
logger.info("Got response %r" % (body,))
44+
logger.info("Got response %r", body)
4945
self.assertIn("sid", body)
5046
self.mailSink.get_mail()
5147

@@ -130,7 +126,7 @@ def test_store_invite(self):
130126
self.assertTrue(is_valid_body["valid"])
131127

132128
mail = self.mailSink.get_mail()
133-
logger.info("Got email (invite): %r" % (mail,))
129+
logger.info("Got email (invite): %r", mail)
134130
mail_object = json.loads(mail["data"])
135131
self.assertEqual(mail_object["token"], body["token"])
136132
self.assertEqual(mail_object["room_alias"], "#alias:fake.test")

integration-tests/matrix_is_tester/fakehs.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# Copyright 2019 The Matrix.org Foundation C.I.C.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,16 +31,16 @@ def token_for_random_user():
3331
The token will represent a random user account.
3432
"""
3533
num = random.randint(0, 2**32)
36-
user_id = "@user%d:127.0.0.1:4490" % (num,)
37-
return "user:%s" % (base64.b64encode(user_id.encode("UTF-8")).decode("UTF-8"),)
34+
user_id = f"@user{num}:127.0.0.1:4490"
35+
return "user:{}".format(base64.b64encode(user_id.encode("UTF-8")).decode("UTF-8"))
3836

3937

4038
def token_for_user(user_id):
4139
"""
4240
Return an OpenID token as would be obtained from the client/server API.
4341
The token will represent the user_id given.
4442
"""
45-
return "user:%s" % (base64.b64encode(user_id.encode("UTF-8")).decode("UTF-8"),)
43+
return "user:{}".format(base64.b64encode(user_id.encode("UTF-8")).decode("UTF-8"))
4644

4745

4846
def get_shared_fake_hs():

integration-tests/matrix_is_tester/is_api.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#!/usr/bin/env python
2-
3-
# -*- coding: utf-8 -*-
4-
51
# Copyright 2019 The Matrix.org Foundation C.I.C.
62
#
73
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +24,7 @@
2824
logger = logging.getLogger(__name__)
2925

3026

31-
class IsApi(object):
27+
class IsApi:
3228
"""
3329
Wrappers around the IS REST API
3430
"""
@@ -52,7 +48,7 @@ def __init__(self, base_url, version, mail_sink):
5248
elif version == "v2":
5349
self.apiRoot = base_url + "/_matrix/identity/v2"
5450
else:
55-
raise Exception("Invalid version: %s" % (version,))
51+
raise Exception(f"Invalid version: {version}")
5652

5753
self.mail_sink = mail_sink
5854

@@ -66,12 +62,12 @@ def make_account(self, hs_addr, openid_token=None):
6662
openid_token = token_for_random_user()
6763

6864
body = self.register(":".join([str(x) for x in hs_addr]), openid_token)
69-
self.headers = {"Authorization": "Bearer %s" % (body["token"],)}
65+
self.headers = {"Authorization": "Bearer {}".format(body["token"])}
7066

7167
def get_token_from_mail(self):
7268
mail = self.mail_sink.get_mail()
7369

74-
log.msg("Got email: %r" % (mail,))
70+
logger.info("Got email: %r", mail)
7571
if "data" not in mail:
7672
raise Exception("Mail has no 'data'")
7773

@@ -122,7 +118,7 @@ def request_and_submit_email_code(self, address):
122118
headers=self.headers,
123119
)
124120
body = resp.json()
125-
log.msg("submitToken returned %r" % (body,))
121+
logger.info("submitToken returned %r", body)
126122
if not body["success"]:
127123
raise Exception("Submit token failed")
128124
return {"sid": sid, "client_secret": client_secret}

integration-tests/matrix_is_tester/launch_is.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#!/usr/bin/env python
2-
3-
# -*- coding: utf-8 -*-
4-
51
# Copyright 2019 The Matrix.org Foundation C.I.C.
62
#
73
# Licensed under the Apache License, Version 2.0 (the "License");

integration-tests/matrix_is_tester/launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def launch(self):
9090
# XXX: wait for startup in a sensible way
9191
time.sleep(2)
9292

93-
self._baseUrl = "http://localhost:%d" % (port,)
93+
self._baseUrl = f"http://localhost:{port}"
9494

9595
def tearDown(self):
9696
print("Stopping sydent...")

integration-tests/matrix_is_tester/mailsink.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# Copyright 2019 The Matrix.org Foundation C.I.C.
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -82,5 +80,5 @@ def tearDown(self):
8280
if __name__ == "__main__":
8381
ms = MailSink()
8482
ms.launch()
85-
print("%r" % (ms.get_mail(),))
83+
print(f"{ms.get_mail()!r}")
8684
ms.tearDown()

integration-tests/matrix_is_tester/test_bind_denied.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#!/usr/bin/env python
2-
3-
# -*- coding: utf-8 -*-
4-
51
# Copyright 2019 The Matrix.org Foundation C.I.C.
62
#
73
# Licensed under the Apache License, Version 2.0 (the "License");

integration-tests/matrix_is_tester/test_v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class V2Test(BaseApiTest, unittest.TestCase):
2626
API_VERSION = "v2"
2727

2828
def setUp(self):
29-
super(V2Test, self).setUp()
29+
super().setUp()
3030

3131
self.fakeHs = get_shared_fake_hs()
3232
self.api.make_account(
@@ -45,7 +45,7 @@ def test_bind_and_lookup(self):
4545

4646
hash_details = self.api.hash_details()
4747

48-
lookup_str = "%s %s" % ("fakeemail3@nowhere.test", "email")
48+
lookup_str = "{} {}".format("fakeemail3@nowhere.test", "email")
4949
body2 = self.api.hashed_lookup(
5050
[lookup_str], "none", hash_details["lookup_pepper"]
5151
)

stubs/twisted/internet/endpoints.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import AnyStr, Optional
1+
from typing import AnyStr
22

33
from twisted.internet import interfaces
44
from twisted.internet.defer import Deferred
@@ -21,8 +21,8 @@ class HostnameEndpoint:
2121
host: AnyStr,
2222
port: int,
2323
timeout: float = ...,
24-
bindAddress: Optional[bytes] = ...,
25-
attemptDelay: Optional[float] = ...,
24+
bindAddress: bytes | None = ...,
25+
attemptDelay: float | None = ...,
2626
): ...
2727
def connect(self, protocol_factory: IProtocolFactory) -> Deferred[IProtocol]: ...
2828

stubs/twisted/internet/error.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import Any, Optional
1+
from typing import Any
22

33
class ConnectError(Exception):
4-
def __init__(self, osError: Optional[Any] = ..., string: str = ...): ...
4+
def __init__(self, osError: Any | None = ..., string: str = ...): ...
55

66
class DNSLookupError(IOError): ...

0 commit comments

Comments
 (0)