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

Commit

Permalink
Simplify super() calls to Python 3 syntax. (#8344)
Browse files Browse the repository at this point in the history
This converts calls like super(Foo, self) -> super().

Generated with:

    sed -i "" -Ee 's/super\([^\(]+\)/super()/g' **/*.py
  • Loading branch information
clokep committed Sep 18, 2020
1 parent 68c7a69 commit 8a4a418
Show file tree
Hide file tree
Showing 133 changed files with 272 additions and 281 deletions.
1 change: 1 addition & 0 deletions changelog.d/8344.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplify `super()` calls to Python 3 syntax.
2 changes: 1 addition & 1 deletion scripts-dev/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class DefinitionVisitor(ast.NodeVisitor):
def __init__(self):
super(DefinitionVisitor, self).__init__()
super().__init__()
self.functions = {}
self.classes = {}
self.names = {}
Expand Down
2 changes: 1 addition & 1 deletion scripts-dev/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def get_connection(self, url, proxies=None):
url = urlparse.urlunparse(
("https", netloc, parsed.path, parsed.params, parsed.query, parsed.fragment)
)
return super(MatrixConnectionAdapter, self).get_connection(url, proxies)
return super().get_connection(url, proxies)


if __name__ == "__main__":
Expand Down
50 changes: 23 additions & 27 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CodeMessageException(RuntimeError):
"""

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

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

def error_dict(self):
Expand All @@ -159,7 +159,7 @@ def __init__(
errcode: str = Codes.UNKNOWN,
additional_fields: Optional[Dict] = None,
):
super(ProxiedRequestError, self).__init__(code, msg, errcode)
super().__init__(code, msg, errcode)
if additional_fields is None:
self._additional_fields = {} # type: Dict
else:
Expand All @@ -181,7 +181,7 @@ def __init__(self, msg: str, consent_uri: str):
msg: The human-readable error message
consent_url: The URL where the user can give their consent
"""
super(ConsentNotGivenError, self).__init__(
super().__init__(
code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.CONSENT_NOT_GIVEN
)
self._consent_uri = consent_uri
Expand All @@ -201,7 +201,7 @@ def __init__(self, msg: str):
Args:
msg: The human-readable error message
"""
super(UserDeactivatedError, self).__init__(
super().__init__(
code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.USER_DEACTIVATED
)

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

self.destination = destination

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

def __init__(self, session_id: str, result: "JsonDict"):
super(InteractiveAuthIncompleteError, self).__init__(
"Interactive auth not yet complete"
)
super().__init__("Interactive auth not yet complete")
self.session_id = session_id
self.result = result

Expand All @@ -261,14 +259,14 @@ def __init__(self, *args, **kwargs):
message = "Unrecognized request"
else:
message = args[0]
super(UnrecognizedRequestError, self).__init__(400, message, **kwargs)
super().__init__(400, message, **kwargs)


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

def __init__(self, msg: str = "Not found", errcode: str = Codes.NOT_FOUND):
super(NotFoundError, self).__init__(404, msg, errcode=errcode)
super().__init__(404, msg, errcode=errcode)


class AuthError(SynapseError):
Expand All @@ -279,7 +277,7 @@ class AuthError(SynapseError):
def __init__(self, *args, **kwargs):
if "errcode" not in kwargs:
kwargs["errcode"] = Codes.FORBIDDEN
super(AuthError, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class InvalidClientCredentialsError(SynapseError):
Expand Down Expand Up @@ -335,7 +333,7 @@ def __init__(
):
self.admin_contact = admin_contact
self.limit_type = limit_type
super(ResourceLimitError, self).__init__(code, msg, errcode=errcode)
super().__init__(code, msg, errcode=errcode)

def error_dict(self):
return cs_error(
Expand All @@ -352,7 +350,7 @@ class EventSizeError(SynapseError):
def __init__(self, *args, **kwargs):
if "errcode" not in kwargs:
kwargs["errcode"] = Codes.TOO_LARGE
super(EventSizeError, self).__init__(413, *args, **kwargs)
super().__init__(413, *args, **kwargs)


class EventStreamError(SynapseError):
Expand All @@ -361,7 +359,7 @@ class EventStreamError(SynapseError):
def __init__(self, *args, **kwargs):
if "errcode" not in kwargs:
kwargs["errcode"] = Codes.BAD_PAGINATION
super(EventStreamError, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class LoginError(SynapseError):
Expand All @@ -384,7 +382,7 @@ def __init__(
error_url: Optional[str] = None,
errcode: str = Codes.CAPTCHA_INVALID,
):
super(InvalidCaptchaError, self).__init__(code, msg, errcode)
super().__init__(code, msg, errcode)
self.error_url = error_url

def error_dict(self):
Expand All @@ -402,7 +400,7 @@ def __init__(
retry_after_ms: Optional[int] = None,
errcode: str = Codes.LIMIT_EXCEEDED,
):
super(LimitExceededError, self).__init__(code, msg, errcode)
super().__init__(code, msg, errcode)
self.retry_after_ms = retry_after_ms

def error_dict(self):
Expand All @@ -418,9 +416,7 @@ def __init__(self, current_version: str):
Args:
current_version: the current version of the store they should have used
"""
super(RoomKeysVersionError, self).__init__(
403, "Wrong room_keys version", Codes.WRONG_ROOM_KEYS_VERSION
)
super().__init__(403, "Wrong room_keys version", Codes.WRONG_ROOM_KEYS_VERSION)
self.current_version = current_version


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

def __init__(self, msg: str = "Homeserver does not support this room version"):
super(UnsupportedRoomVersionError, self).__init__(
super().__init__(
code=400, msg=msg, errcode=Codes.UNSUPPORTED_ROOM_VERSION,
)

Expand All @@ -440,7 +436,7 @@ class ThreepidValidationError(SynapseError):
def __init__(self, *args, **kwargs):
if "errcode" not in kwargs:
kwargs["errcode"] = Codes.FORBIDDEN
super(ThreepidValidationError, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class IncompatibleRoomVersionError(SynapseError):
Expand All @@ -451,7 +447,7 @@ class IncompatibleRoomVersionError(SynapseError):
"""

def __init__(self, room_version: str):
super(IncompatibleRoomVersionError, self).__init__(
super().__init__(
code=400,
msg="Your homeserver does not support the features required to "
"join this room",
Expand All @@ -473,7 +469,7 @@ def __init__(
msg: str = "This password doesn't comply with the server's policy",
errcode: str = Codes.WEAK_PASSWORD,
):
super(PasswordRefusedError, self).__init__(
super().__init__(
code=400, msg=msg, errcode=errcode,
)

Expand All @@ -488,7 +484,7 @@ class RequestSendFailed(RuntimeError):
"""

def __init__(self, inner_exception, can_retry):
super(RequestSendFailed, self).__init__(
super().__init__(
"Failed to send request: %s: %s"
% (type(inner_exception).__name__, inner_exception)
)
Expand Down Expand Up @@ -542,7 +538,7 @@ def __init__(
self.source = source

msg = "%s %s: %s" % (level, code, reason)
super(FederationError, self).__init__(msg)
super().__init__(msg)

def get_dict(self):
return {
Expand Down Expand Up @@ -570,7 +566,7 @@ def __init__(self, code: int, msg: str, response: bytes):
msg: reason phrase from HTTP response status line
response: body of response
"""
super(HttpResponseException, self).__init__(code, msg)
super().__init__(code, msg)
self.response = response

def to_synapse_error(self):
Expand Down
2 changes: 1 addition & 1 deletion synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def matrix_user_id_validator(user_id_str):

class Filtering:
def __init__(self, hs):
super(Filtering, self).__init__()
super().__init__()
self.store = hs.get_datastore()

async def get_user_filter(self, user_localpart, filter_id):
Expand Down
6 changes: 3 additions & 3 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class PresenceStatusStubServlet(RestServlet):
PATTERNS = client_patterns("/presence/(?P<user_id>[^/]*)/status")

def __init__(self, hs):
super(PresenceStatusStubServlet, self).__init__()
super().__init__()
self.auth = hs.get_auth()

async def on_GET(self, request, user_id):
Expand All @@ -176,7 +176,7 @@ def __init__(self, hs):
Args:
hs (synapse.server.HomeServer): server
"""
super(KeyUploadServlet, self).__init__()
super().__init__()
self.auth = hs.get_auth()
self.store = hs.get_datastore()
self.http_client = hs.get_simple_http_client()
Expand Down Expand Up @@ -646,7 +646,7 @@ def get_presence_handler(self):

class GenericWorkerReplicationHandler(ReplicationDataHandler):
def __init__(self, hs):
super(GenericWorkerReplicationHandler, self).__init__(hs)
super().__init__(hs)

self.store = hs.get_datastore()
self.presence_handler = hs.get_presence_handler() # type: GenericWorkerPresence
Expand Down
2 changes: 1 addition & 1 deletion synapse/appservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ApplicationServiceApi(SimpleHttpClient):
"""

def __init__(self, hs):
super(ApplicationServiceApi, self).__init__(hs)
super().__init__(hs)
self.clock = hs.get_clock()

self.protocol_meta_cache = ResponseCache(
Expand Down
2 changes: 1 addition & 1 deletion synapse/config/consent_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ConsentConfig(Config):
section = "consent"

def __init__(self, *args):
super(ConsentConfig, self).__init__(*args)
super().__init__(*args)

self.user_consent_version = None
self.user_consent_template_dir = None
Expand Down
2 changes: 1 addition & 1 deletion synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AccountValidityConfig(Config):
def __init__(self, config, synapse_config):
if config is None:
return
super(AccountValidityConfig, self).__init__()
super().__init__()
self.enabled = config.get("enabled", False)
self.renew_by_email_enabled = "renew_at" in config

Expand Down
2 changes: 1 addition & 1 deletion synapse/config/server_notices_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ServerNoticesConfig(Config):
section = "servernotices"

def __init__(self, *args):
super(ServerNoticesConfig, self).__init__(*args)
super().__init__(*args)
self.server_notices_mxid = None
self.server_notices_mxid_display_name = None
self.server_notices_mxid_avatar_url = None
Expand Down
4 changes: 2 additions & 2 deletions synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class PerspectivesKeyFetcher(BaseV2KeyFetcher):
"""KeyFetcher impl which fetches keys from the "perspectives" servers"""

def __init__(self, hs):
super(PerspectivesKeyFetcher, self).__init__(hs)
super().__init__(hs)
self.clock = hs.get_clock()
self.client = hs.get_http_client()
self.key_servers = self.config.key_servers
Expand Down Expand Up @@ -728,7 +728,7 @@ class ServerKeyFetcher(BaseV2KeyFetcher):
"""KeyFetcher impl which fetches keys from the origin servers"""

def __init__(self, hs):
super(ServerKeyFetcher, self).__init__(hs)
super().__init__(hs)
self.clock = hs.get_clock()
self.client = hs.get_http_client()

Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class InvalidResponseError(RuntimeError):

class FederationClient(FederationBase):
def __init__(self, hs):
super(FederationClient, self).__init__(hs)
super().__init__(hs)

self.pdu_destination_tried = {}
self._clock.looping_call(self._clear_tried_cache, 60 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

class FederationServer(FederationBase):
def __init__(self, hs):
super(FederationServer, self).__init__(hs)
super().__init__(hs)

self.auth = hs.get_auth()
self.handler = hs.get_handlers().federation_handler
Expand Down
10 changes: 3 additions & 7 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, hs, servlet_groups=None):
self.clock = hs.get_clock()
self.servlet_groups = servlet_groups

super(TransportLayerServer, self).__init__(hs, canonical_json=False)
super().__init__(hs, canonical_json=False)

self.authenticator = Authenticator(hs)
self.ratelimiter = hs.get_federation_ratelimiter()
Expand Down Expand Up @@ -376,9 +376,7 @@ class FederationSendServlet(BaseFederationServlet):
RATELIMIT = False

def __init__(self, handler, server_name, **kwargs):
super(FederationSendServlet, self).__init__(
handler, server_name=server_name, **kwargs
)
super().__init__(handler, server_name=server_name, **kwargs)
self.server_name = server_name

# This is when someone is trying to send us a bunch of data.
Expand Down Expand Up @@ -773,9 +771,7 @@ class PublicRoomList(BaseFederationServlet):
PATH = "/publicRooms"

def __init__(self, handler, authenticator, ratelimiter, server_name, allow_access):
super(PublicRoomList, self).__init__(
handler, authenticator, ratelimiter, server_name
)
super().__init__(handler, authenticator, ratelimiter, server_name)
self.allow_access = allow_access

async def on_GET(self, origin, content, query):
Expand Down
2 changes: 1 addition & 1 deletion synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ async def get_rooms_in_group(self, group_id, requester_user_id):

class GroupsServerHandler(GroupsServerWorkerHandler):
def __init__(self, hs):
super(GroupsServerHandler, self).__init__(hs)
super().__init__(hs)

# Ensure attestations get renewed
hs.get_groups_attestation_renewer()
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class AdminHandler(BaseHandler):
def __init__(self, hs):
super(AdminHandler, self).__init__(hs)
super().__init__(hs)

self.storage = hs.get_storage()
self.state_store = self.storage.state
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(self, hs):
Args:
hs (synapse.server.HomeServer):
"""
super(AuthHandler, self).__init__(hs)
super().__init__(hs)

self.checkers = {} # type: Dict[str, UserInteractiveAuthChecker]
for auth_checker_class in INTERACTIVE_AUTH_CHECKERS:
Expand Down
Loading

0 comments on commit 8a4a418

Please sign in to comment.