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

Commit 8a4a418

Browse files
authored
Simplify super() calls to Python 3 syntax. (#8344)
This converts calls like super(Foo, self) -> super(). Generated with: sed -i "" -Ee 's/super\([^\(]+\)/super()/g' **/*.py
1 parent 68c7a69 commit 8a4a418

File tree

133 files changed

+272
-281
lines changed

Some content is hidden

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

133 files changed

+272
-281
lines changed

changelog.d/8344.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Simplify `super()` calls to Python 3 syntax.

scripts-dev/definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class DefinitionVisitor(ast.NodeVisitor):
1313
def __init__(self):
14-
super(DefinitionVisitor, self).__init__()
14+
super().__init__()
1515
self.functions = {}
1616
self.classes = {}
1717
self.names = {}

scripts-dev/federation_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def get_connection(self, url, proxies=None):
321321
url = urlparse.urlunparse(
322322
("https", netloc, parsed.path, parsed.params, parsed.query, parsed.fragment)
323323
)
324-
return super(MatrixConnectionAdapter, self).get_connection(url, proxies)
324+
return super().get_connection(url, proxies)
325325

326326

327327
if __name__ == "__main__":

synapse/api/errors.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CodeMessageException(RuntimeError):
8787
"""
8888

8989
def __init__(self, code: Union[int, HTTPStatus], msg: str):
90-
super(CodeMessageException, self).__init__("%d: %s" % (code, msg))
90+
super().__init__("%d: %s" % (code, msg))
9191

9292
# Some calls to this method pass instances of http.HTTPStatus for `code`.
9393
# While HTTPStatus is a subclass of int, it has magic __str__ methods
@@ -138,7 +138,7 @@ def __init__(self, code: int, msg: str, errcode: str = Codes.UNKNOWN):
138138
msg: The human-readable error message.
139139
errcode: The matrix error code e.g 'M_FORBIDDEN'
140140
"""
141-
super(SynapseError, self).__init__(code, msg)
141+
super().__init__(code, msg)
142142
self.errcode = errcode
143143

144144
def error_dict(self):
@@ -159,7 +159,7 @@ def __init__(
159159
errcode: str = Codes.UNKNOWN,
160160
additional_fields: Optional[Dict] = None,
161161
):
162-
super(ProxiedRequestError, self).__init__(code, msg, errcode)
162+
super().__init__(code, msg, errcode)
163163
if additional_fields is None:
164164
self._additional_fields = {} # type: Dict
165165
else:
@@ -181,7 +181,7 @@ def __init__(self, msg: str, consent_uri: str):
181181
msg: The human-readable error message
182182
consent_url: The URL where the user can give their consent
183183
"""
184-
super(ConsentNotGivenError, self).__init__(
184+
super().__init__(
185185
code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.CONSENT_NOT_GIVEN
186186
)
187187
self._consent_uri = consent_uri
@@ -201,7 +201,7 @@ def __init__(self, msg: str):
201201
Args:
202202
msg: The human-readable error message
203203
"""
204-
super(UserDeactivatedError, self).__init__(
204+
super().__init__(
205205
code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.USER_DEACTIVATED
206206
)
207207

@@ -225,7 +225,7 @@ def __init__(self, destination: Optional[str]):
225225

226226
self.destination = destination
227227

228-
super(FederationDeniedError, self).__init__(
228+
super().__init__(
229229
code=403,
230230
msg="Federation denied with %s." % (self.destination,),
231231
errcode=Codes.FORBIDDEN,
@@ -244,9 +244,7 @@ class InteractiveAuthIncompleteError(Exception):
244244
"""
245245

246246
def __init__(self, session_id: str, result: "JsonDict"):
247-
super(InteractiveAuthIncompleteError, self).__init__(
248-
"Interactive auth not yet complete"
249-
)
247+
super().__init__("Interactive auth not yet complete")
250248
self.session_id = session_id
251249
self.result = result
252250

@@ -261,14 +259,14 @@ def __init__(self, *args, **kwargs):
261259
message = "Unrecognized request"
262260
else:
263261
message = args[0]
264-
super(UnrecognizedRequestError, self).__init__(400, message, **kwargs)
262+
super().__init__(400, message, **kwargs)
265263

266264

267265
class NotFoundError(SynapseError):
268266
"""An error indicating we can't find the thing you asked for"""
269267

270268
def __init__(self, msg: str = "Not found", errcode: str = Codes.NOT_FOUND):
271-
super(NotFoundError, self).__init__(404, msg, errcode=errcode)
269+
super().__init__(404, msg, errcode=errcode)
272270

273271

274272
class AuthError(SynapseError):
@@ -279,7 +277,7 @@ class AuthError(SynapseError):
279277
def __init__(self, *args, **kwargs):
280278
if "errcode" not in kwargs:
281279
kwargs["errcode"] = Codes.FORBIDDEN
282-
super(AuthError, self).__init__(*args, **kwargs)
280+
super().__init__(*args, **kwargs)
283281

284282

285283
class InvalidClientCredentialsError(SynapseError):
@@ -335,7 +333,7 @@ def __init__(
335333
):
336334
self.admin_contact = admin_contact
337335
self.limit_type = limit_type
338-
super(ResourceLimitError, self).__init__(code, msg, errcode=errcode)
336+
super().__init__(code, msg, errcode=errcode)
339337

340338
def error_dict(self):
341339
return cs_error(
@@ -352,7 +350,7 @@ class EventSizeError(SynapseError):
352350
def __init__(self, *args, **kwargs):
353351
if "errcode" not in kwargs:
354352
kwargs["errcode"] = Codes.TOO_LARGE
355-
super(EventSizeError, self).__init__(413, *args, **kwargs)
353+
super().__init__(413, *args, **kwargs)
356354

357355

358356
class EventStreamError(SynapseError):
@@ -361,7 +359,7 @@ class EventStreamError(SynapseError):
361359
def __init__(self, *args, **kwargs):
362360
if "errcode" not in kwargs:
363361
kwargs["errcode"] = Codes.BAD_PAGINATION
364-
super(EventStreamError, self).__init__(*args, **kwargs)
362+
super().__init__(*args, **kwargs)
365363

366364

367365
class LoginError(SynapseError):
@@ -384,7 +382,7 @@ def __init__(
384382
error_url: Optional[str] = None,
385383
errcode: str = Codes.CAPTCHA_INVALID,
386384
):
387-
super(InvalidCaptchaError, self).__init__(code, msg, errcode)
385+
super().__init__(code, msg, errcode)
388386
self.error_url = error_url
389387

390388
def error_dict(self):
@@ -402,7 +400,7 @@ def __init__(
402400
retry_after_ms: Optional[int] = None,
403401
errcode: str = Codes.LIMIT_EXCEEDED,
404402
):
405-
super(LimitExceededError, self).__init__(code, msg, errcode)
403+
super().__init__(code, msg, errcode)
406404
self.retry_after_ms = retry_after_ms
407405

408406
def error_dict(self):
@@ -418,9 +416,7 @@ def __init__(self, current_version: str):
418416
Args:
419417
current_version: the current version of the store they should have used
420418
"""
421-
super(RoomKeysVersionError, self).__init__(
422-
403, "Wrong room_keys version", Codes.WRONG_ROOM_KEYS_VERSION
423-
)
419+
super().__init__(403, "Wrong room_keys version", Codes.WRONG_ROOM_KEYS_VERSION)
424420
self.current_version = current_version
425421

426422

@@ -429,7 +425,7 @@ class UnsupportedRoomVersionError(SynapseError):
429425
not support."""
430426

431427
def __init__(self, msg: str = "Homeserver does not support this room version"):
432-
super(UnsupportedRoomVersionError, self).__init__(
428+
super().__init__(
433429
code=400, msg=msg, errcode=Codes.UNSUPPORTED_ROOM_VERSION,
434430
)
435431

@@ -440,7 +436,7 @@ class ThreepidValidationError(SynapseError):
440436
def __init__(self, *args, **kwargs):
441437
if "errcode" not in kwargs:
442438
kwargs["errcode"] = Codes.FORBIDDEN
443-
super(ThreepidValidationError, self).__init__(*args, **kwargs)
439+
super().__init__(*args, **kwargs)
444440

445441

446442
class IncompatibleRoomVersionError(SynapseError):
@@ -451,7 +447,7 @@ class IncompatibleRoomVersionError(SynapseError):
451447
"""
452448

453449
def __init__(self, room_version: str):
454-
super(IncompatibleRoomVersionError, self).__init__(
450+
super().__init__(
455451
code=400,
456452
msg="Your homeserver does not support the features required to "
457453
"join this room",
@@ -473,7 +469,7 @@ def __init__(
473469
msg: str = "This password doesn't comply with the server's policy",
474470
errcode: str = Codes.WEAK_PASSWORD,
475471
):
476-
super(PasswordRefusedError, self).__init__(
472+
super().__init__(
477473
code=400, msg=msg, errcode=errcode,
478474
)
479475

@@ -488,7 +484,7 @@ class RequestSendFailed(RuntimeError):
488484
"""
489485

490486
def __init__(self, inner_exception, can_retry):
491-
super(RequestSendFailed, self).__init__(
487+
super().__init__(
492488
"Failed to send request: %s: %s"
493489
% (type(inner_exception).__name__, inner_exception)
494490
)
@@ -542,7 +538,7 @@ def __init__(
542538
self.source = source
543539

544540
msg = "%s %s: %s" % (level, code, reason)
545-
super(FederationError, self).__init__(msg)
541+
super().__init__(msg)
546542

547543
def get_dict(self):
548544
return {
@@ -570,7 +566,7 @@ def __init__(self, code: int, msg: str, response: bytes):
570566
msg: reason phrase from HTTP response status line
571567
response: body of response
572568
"""
573-
super(HttpResponseException, self).__init__(code, msg)
569+
super().__init__(code, msg)
574570
self.response = response
575571

576572
def to_synapse_error(self):

synapse/api/filtering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def matrix_user_id_validator(user_id_str):
132132

133133
class Filtering:
134134
def __init__(self, hs):
135-
super(Filtering, self).__init__()
135+
super().__init__()
136136
self.store = hs.get_datastore()
137137

138138
async def get_user_filter(self, user_localpart, filter_id):

synapse/app/generic_worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class PresenceStatusStubServlet(RestServlet):
152152
PATTERNS = client_patterns("/presence/(?P<user_id>[^/]*)/status")
153153

154154
def __init__(self, hs):
155-
super(PresenceStatusStubServlet, self).__init__()
155+
super().__init__()
156156
self.auth = hs.get_auth()
157157

158158
async def on_GET(self, request, user_id):
@@ -176,7 +176,7 @@ def __init__(self, hs):
176176
Args:
177177
hs (synapse.server.HomeServer): server
178178
"""
179-
super(KeyUploadServlet, self).__init__()
179+
super().__init__()
180180
self.auth = hs.get_auth()
181181
self.store = hs.get_datastore()
182182
self.http_client = hs.get_simple_http_client()
@@ -646,7 +646,7 @@ def get_presence_handler(self):
646646

647647
class GenericWorkerReplicationHandler(ReplicationDataHandler):
648648
def __init__(self, hs):
649-
super(GenericWorkerReplicationHandler, self).__init__(hs)
649+
super().__init__(hs)
650650

651651
self.store = hs.get_datastore()
652652
self.presence_handler = hs.get_presence_handler() # type: GenericWorkerPresence

synapse/appservice/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ApplicationServiceApi(SimpleHttpClient):
8888
"""
8989

9090
def __init__(self, hs):
91-
super(ApplicationServiceApi, self).__init__(hs)
91+
super().__init__(hs)
9292
self.clock = hs.get_clock()
9393

9494
self.protocol_meta_cache = ResponseCache(

synapse/config/consent_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ConsentConfig(Config):
7777
section = "consent"
7878

7979
def __init__(self, *args):
80-
super(ConsentConfig, self).__init__(*args)
80+
super().__init__(*args)
8181

8282
self.user_consent_version = None
8383
self.user_consent_template_dir = None

synapse/config/registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AccountValidityConfig(Config):
3030
def __init__(self, config, synapse_config):
3131
if config is None:
3232
return
33-
super(AccountValidityConfig, self).__init__()
33+
super().__init__()
3434
self.enabled = config.get("enabled", False)
3535
self.renew_by_email_enabled = "renew_at" in config
3636

synapse/config/server_notices_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ServerNoticesConfig(Config):
6262
section = "servernotices"
6363

6464
def __init__(self, *args):
65-
super(ServerNoticesConfig, self).__init__(*args)
65+
super().__init__(*args)
6666
self.server_notices_mxid = None
6767
self.server_notices_mxid_display_name = None
6868
self.server_notices_mxid_avatar_url = None

0 commit comments

Comments
 (0)