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

Replace returnValue with return #5736

Merged
merged 11 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5736.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace uses of returnValue with plain return, as returnValue is not needed on Python 3.
2 changes: 1 addition & 1 deletion docs/log_contexts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ call any other functions.
d = more_stuff()
result = yield d # also fine, of course

defer.returnValue(result)
return result

def nonInlineCallbacksFun():
logger.debug("just a wrapper really")
Expand Down
44 changes: 20 additions & 24 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def check_joined_room(self, room_id, user_id, current_state=None):
)

self._check_joined_room(member, user_id, room_id)
defer.returnValue(member)
return member

@defer.inlineCallbacks
def check_user_was_in_room(self, room_id, user_id):
Expand Down Expand Up @@ -156,13 +156,13 @@ def check_user_was_in_room(self, room_id, user_id):
if forgot:
raise AuthError(403, "User %s not in room %s" % (user_id, room_id))

defer.returnValue(member)
return member

@defer.inlineCallbacks
def check_host_in_room(self, room_id, host):
with Measure(self.clock, "check_host_in_room"):
latest_event_ids = yield self.store.is_host_joined(room_id, host)
defer.returnValue(latest_event_ids)
return latest_event_ids

def _check_joined_room(self, member, user_id, room_id):
if not member or member.membership != Membership.JOIN:
Expand Down Expand Up @@ -219,9 +219,7 @@ def get_user_by_req(
device_id="dummy-device", # stubbed
)

defer.returnValue(
synapse.types.create_requester(user_id, app_service=app_service)
)
return synapse.types.create_requester(user_id, app_service=app_service)

user_info = yield self.get_user_by_access_token(access_token, rights)
user = user_info["user"]
Expand Down Expand Up @@ -262,10 +260,8 @@ def get_user_by_req(

request.authenticated_entity = user.to_string()

defer.returnValue(
synapse.types.create_requester(
user, token_id, is_guest, device_id, app_service=app_service
)
return synapse.types.create_requester(
user, token_id, is_guest, device_id, app_service=app_service
)
except KeyError:
raise MissingClientTokenError()
Expand All @@ -276,25 +272,25 @@ def _get_appservice_user_id(self, request):
self.get_access_token_from_request(request)
)
if app_service is None:
defer.returnValue((None, None))
return (None, None)

if app_service.ip_range_whitelist:
ip_address = IPAddress(self.hs.get_ip_from_request(request))
if ip_address not in app_service.ip_range_whitelist:
defer.returnValue((None, None))
return (None, None)

if b"user_id" not in request.args:
defer.returnValue((app_service.sender, app_service))
return (app_service.sender, app_service)

user_id = request.args[b"user_id"][0].decode("utf8")
if app_service.sender == user_id:
defer.returnValue((app_service.sender, app_service))
return (app_service.sender, app_service)

if not app_service.is_interested_in_user(user_id):
raise AuthError(403, "Application service cannot masquerade as this user.")
if not (yield self.store.get_user_by_id(user_id)):
raise AuthError(403, "Application service has not registered this user")
defer.returnValue((user_id, app_service))
return (user_id, app_service)

@defer.inlineCallbacks
def get_user_by_access_token(self, token, rights="access"):
Expand Down Expand Up @@ -330,7 +326,7 @@ def get_user_by_access_token(self, token, rights="access"):
msg="Access token has expired", soft_logout=True
)

defer.returnValue(r)
return r

# otherwise it needs to be a valid macaroon
try:
Expand Down Expand Up @@ -378,7 +374,7 @@ def get_user_by_access_token(self, token, rights="access"):
}
else:
raise RuntimeError("Unknown rights setting %s", rights)
defer.returnValue(ret)
return ret
except (
_InvalidMacaroonException,
pymacaroons.exceptions.MacaroonException,
Expand Down Expand Up @@ -506,7 +502,7 @@ def _verify_expiry(self, caveat):
def _look_up_user_by_access_token(self, token):
ret = yield self.store.get_user_by_access_token(token)
if not ret:
defer.returnValue(None)
return None

# we use ret.get() below because *lots* of unit tests stub out
# get_user_by_access_token in a way where it only returns a couple of
Expand All @@ -518,7 +514,7 @@ def _look_up_user_by_access_token(self, token):
"device_id": ret.get("device_id"),
"valid_until_ms": ret.get("valid_until_ms"),
}
defer.returnValue(user_info)
return user_info

def get_appservice_by_req(self, request):
token = self.get_access_token_from_request(request)
Expand All @@ -543,7 +539,7 @@ def is_server_admin(self, user):
@defer.inlineCallbacks
def compute_auth_events(self, event, current_state_ids, for_verification=False):
if event.type == EventTypes.Create:
defer.returnValue([])
return []

auth_ids = []

Expand Down Expand Up @@ -604,7 +600,7 @@ def compute_auth_events(self, event, current_state_ids, for_verification=False):
if member_event.content["membership"] == Membership.JOIN:
auth_ids.append(member_event.event_id)

defer.returnValue(auth_ids)
return auth_ids

@defer.inlineCallbacks
def check_can_change_room_list(self, room_id, user):
Expand All @@ -618,7 +614,7 @@ def check_can_change_room_list(self, room_id, user):

is_admin = yield self.is_server_admin(user)
if is_admin:
defer.returnValue(True)
return True

user_id = user.to_string()
yield self.check_joined_room(room_id, user_id)
Expand Down Expand Up @@ -712,7 +708,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
# * The user is a guest user, and has joined the room
# else it will throw.
member_event = yield self.check_user_was_in_room(room_id, user_id)
defer.returnValue((member_event.membership, member_event.event_id))
return (member_event.membership, member_event.event_id)
except AuthError:
visibility = yield self.state.get_current_state(
room_id, EventTypes.RoomHistoryVisibility, ""
Expand All @@ -721,7 +717,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
visibility
and visibility.content["history_visibility"] == "world_readable"
):
defer.returnValue((Membership.JOIN, None))
return (Membership.JOIN, None)
return
raise AuthError(
403, "Guest access not allowed", errcode=Codes.GUEST_ACCESS_FORBIDDEN
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 __init__(self, hs):
@defer.inlineCallbacks
def get_user_filter(self, user_localpart, filter_id):
result = yield self.store.get_user_filter(user_localpart, filter_id)
defer.returnValue(FilterCollection(result))
return FilterCollection(result)

def add_user_filter(self, user_localpart, user_filter):
self.check_valid_filter(user_filter)
Expand Down
8 changes: 4 additions & 4 deletions synapse/app/frontend_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def on_GET(self, request, user_id):
except HttpResponseException as e:
raise e.to_synapse_error()

defer.returnValue((200, result))
return (200, result)

@defer.inlineCallbacks
def on_PUT(self, request, user_id):
yield self.auth.get_user_by_req(request)
defer.returnValue((200, {}))
return (200, {})


class KeyUploadServlet(RestServlet):
Expand Down Expand Up @@ -126,11 +126,11 @@ def on_POST(self, request, device_id):
self.main_uri + request.uri.decode("ascii"), body, headers=headers
)

defer.returnValue((200, result))
return (200, result)
else:
# Just interested in counts.
result = yield self.store.count_e2e_one_time_keys(user_id, device_id)
defer.returnValue((200, {"one_time_key_counts": result}))
return (200, {"one_time_key_counts": result})


class FrontendProxySlavedStore(
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/homeserver.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def do_acme():
if provision:
yield acme.provision_certificate()

defer.returnValue(provision)
return provision

@defer.inlineCallbacks
def reprovision_acme():
Expand Down
28 changes: 14 additions & 14 deletions synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,21 @@ def _is_exclusive(self, ns_key, test_string):
@defer.inlineCallbacks
def _matches_user(self, event, store):
if not event:
defer.returnValue(False)
return False

if self.is_interested_in_user(event.sender):
defer.returnValue(True)
return True
# also check m.room.member state key
if event.type == EventTypes.Member and self.is_interested_in_user(
event.state_key
):
defer.returnValue(True)
return True

if not store:
defer.returnValue(False)
return False

does_match = yield self._matches_user_in_member_list(event.room_id, store)
defer.returnValue(does_match)
return does_match

@cachedInlineCallbacks(num_args=1, cache_context=True)
def _matches_user_in_member_list(self, room_id, store, cache_context):
Expand All @@ -200,8 +200,8 @@ def _matches_user_in_member_list(self, room_id, store, cache_context):
# check joined member events
for user_id in member_list:
if self.is_interested_in_user(user_id):
defer.returnValue(True)
defer.returnValue(False)
return True
return False

def _matches_room_id(self, event):
if hasattr(event, "room_id"):
Expand All @@ -211,13 +211,13 @@ def _matches_room_id(self, event):
@defer.inlineCallbacks
def _matches_aliases(self, event, store):
if not store or not event:
defer.returnValue(False)
return False

alias_list = yield store.get_aliases_for_room(event.room_id)
for alias in alias_list:
if self.is_interested_in_alias(alias):
defer.returnValue(True)
defer.returnValue(False)
return True
return False

@defer.inlineCallbacks
def is_interested(self, event, store=None):
Expand All @@ -231,15 +231,15 @@ def is_interested(self, event, store=None):
"""
# Do cheap checks first
if self._matches_room_id(event):
defer.returnValue(True)
return True

if (yield self._matches_aliases(event, store)):
defer.returnValue(True)
return True

if (yield self._matches_user(event, store)):
defer.returnValue(True)
return True

defer.returnValue(False)
return False

def is_interested_in_user(self, user_id):
return (
Expand Down
Loading