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

Commit

Permalink
Fix-up some return type hints.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Nov 10, 2022
1 parent 547a626 commit a36e5a6
Show file tree
Hide file tree
Showing 30 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def to_synapse_error(self) -> SynapseError:
set to the reason code from the HTTP response.
Returns:
SynapseError:
The error converted to a SynapseError.
"""
# try to parse the body as json, to get better errcode/msg, but
# default to M_UNKNOWN with the HTTP status as the error text
Expand Down
9 changes: 4 additions & 5 deletions synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def verify_json_for_server(

def verify_json_objects_for_server(
self, server_and_json: Iterable[Tuple[str, dict, int]]
) -> List[defer.Deferred]:
) -> List["defer.Deferred[None]"]:
"""Bulk verifies signatures of json objects, bulk fetching keys as
necessary.
Expand All @@ -226,10 +226,9 @@ def verify_json_objects_for_server(
valid.
Returns:
List<Deferred[None]>: for each input triplet, a deferred indicating success
or failure to verify each json object's signature for the given
server_name. The deferreds run their callbacks in the sentinel
logcontext.
For each input triplet, a deferred indicating success or failure to
verify each json object's signature for the given server_name. The
deferreds run their callbacks in the sentinel logcontext.
"""
return [
run_in_background(
Expand Down
3 changes: 1 addition & 2 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,7 @@ def _event_type_from_format_version(
format_version: The event format version
Returns:
type: A type that can be initialized as per the initializer of
`FrozenEvent`
A type that can be initialized as per the initializer of `FrozenEvent`
"""

if format_version == EventFormatVersions.ROOM_V1_V2:
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ async def _fetch_userinfo(self, token: Token) -> UserInfo:
Must include an ``access_token`` field.
Returns:
UserInfo: an object representing the user.
an object representing the user.
"""
logger.debug("Using the OAuth2 access_token to request userinfo")
metadata = await self.load_metadata()
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async def current_state_for_users(
"""Get the current presence state for multiple users.
Returns:
dict: `user_id` -> `UserPresenceState`
A mapping of `user_id` -> `UserPresenceState`
"""
states = {}
missing = []
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def saml_response_to_user_attributes(
client_redirect_url: where the client wants to redirect to
Returns:
dict: A dict containing new user attributes. Possible keys:
A dict containing new user attributes. Possible keys:
* mxid_localpart (str): Required. The localpart of the user's mxid
* displayname (str): The displayname of the user
* emails (list[str]): Any emails for the user
Expand Down Expand Up @@ -483,7 +483,7 @@ def parse_config(config: dict) -> SamlConfig:
Args:
config: A dictionary containing configuration options for this provider
Returns:
SamlConfig: A custom config object for this module
A custom config object for this module
"""
# Parse config options and use defaults where necessary
mxid_source_attribute = config.get("mxid_source_attribute", "uid")
Expand Down
9 changes: 4 additions & 5 deletions synapse/http/federation/matrix_federation_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ def request(
a file for a file upload). Or None if the request is to have
no body.
Returns:
Deferred[twisted.web.iweb.IResponse]:
fires when the header of the response has been received (regardless of the
response status code). Fails if there is any problem which prevents that
response from being received (including problems that prevent the request
from being sent).
A deferred which fires when the header of the response has been received
(regardless of the response status code). Fails if there is any problem
which prevents that response from being received (including problems that
prevent the request from being sent).
"""
# We use urlparse as that will set `port` to None if there is no
# explicit port.
Expand Down
3 changes: 1 addition & 2 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,7 @@ async def post_json(
args: query params
Returns:
dict|list: Succeeds when we get a 2xx HTTP response. The
result will be the decoded JSON body.
Succeeds when we get a 2xx HTTP response. The result will be the decoded JSON body.
Raises:
HttpResponseException: If we get an HTTP response code >= 300
Expand Down
20 changes: 10 additions & 10 deletions synapse/http/proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
from twisted.web.error import SchemeNotSupported
from twisted.web.http_headers import Headers
from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS
from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS, IResponse

from synapse.http import redact_uri
from synapse.http.connectproxyclient import HTTPConnectProxyEndpoint, ProxyCredentials
Expand Down Expand Up @@ -134,7 +134,7 @@ def request(
uri: bytes,
headers: Optional[Headers] = None,
bodyProducer: Optional[IBodyProducer] = None,
) -> defer.Deferred:
) -> "defer.Deferred[IResponse]":
"""
Issue a request to the server indicated by the given uri.
Expand All @@ -157,17 +157,17 @@ def request(
a file upload). Or, None if the request is to have no body.
Returns:
Deferred[IResponse]: completes when the header of the response has
been received (regardless of the response status code).
A deferred which completes when the header of the response has
been received (regardless of the response status code).
Can fail with:
SchemeNotSupported: if the uri is not http or https
Can fail with:
SchemeNotSupported: if the uri is not http or https
twisted.internet.error.TimeoutError if the server we are connecting
to (proxy or destination) does not accept a connection before
connectTimeout.
twisted.internet.error.TimeoutError if the server we are connecting
to (proxy or destination) does not accept a connection before
connectTimeout.
... other things too.
... other things too.
"""
uri = uri.strip()
if not _VALID_URI.match(uri):
Expand Down
11 changes: 5 additions & 6 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def current_context(cls) -> LoggingContextOrSentinel:
called directly.
Returns:
LoggingContext: the current logging context
The current logging context
"""
warnings.warn(
"synapse.logging.context.LoggingContext.current_context() is deprecated "
Expand Down Expand Up @@ -473,8 +473,7 @@ def get_resource_usage(self) -> ContextResourceUsage:
"""Get resources used by this logcontext so far.
Returns:
ContextResourceUsage: a *copy* of the object tracking resource
usage so far
A *copy* of the object tracking resource usage so far
"""
# we always return a copy, for consistency
res = self._resource_usage.copy()
Expand Down Expand Up @@ -699,7 +698,7 @@ def nested_logging_context(suffix: str) -> LoggingContext:
suffix: suffix to add to the parent context's 'name'.
Returns:
LoggingContext: new logging context.
A new logging context.
"""
curr_context = current_context()
if not curr_context:
Expand Down Expand Up @@ -909,7 +908,7 @@ def defer_to_thread(
kwargs: keyword arguments to pass to f.
Returns:
Deferred: A Deferred which fires a callback with the result of `f`, or an
A Deferred which fires a callback with the result of `f`, or an
errback if `f` throws an exception.
"""
return defer_to_threadpool(reactor, reactor.getThreadPool(), f, *args, **kwargs)
Expand Down Expand Up @@ -950,7 +949,7 @@ def defer_to_threadpool(
kwargs: keyword arguments to pass to f.
Returns:
Deferred: A Deferred which fires a callback with the result of `f`, or an
A Deferred which fires a callback with the result of `f`, or an
errback if `f` throws an exception.
"""
curr_context = current_context()
Expand Down
2 changes: 1 addition & 1 deletion synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def get_active_span_text_map(destination: Optional[str] = None) -> Dict[str, str
destination: the name of the remote server.
Returns:
dict: the active span's context if opentracing is enabled, otherwise empty.
the active span's context if opentracing is enabled, otherwise empty.
"""

if destination and not whitelisted_homeserver(destination):
Expand Down
5 changes: 2 additions & 3 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def run_db_interaction(
**kwargs: named args to be passed to func
Returns:
Deferred[object]: result of func
Result of func
"""
# type-ignore: See https://github.com/python/mypy/issues/8862
return defer.ensureDeferred(
Expand Down Expand Up @@ -924,8 +924,7 @@ def get_state_events_in_room(
to represent 'any') of the room state to acquire.
Returns:
twisted.internet.defer.Deferred[list(synapse.events.FrozenEvent)]:
The filtered state events in the room.
The filtered state events in the room.
"""
state_ids = yield defer.ensureDeferred(
self._storage_controllers.state.get_current_state_ids(
Expand Down
2 changes: 1 addition & 1 deletion synapse/replication/http/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async def _serialize_payload(**kwargs) -> JsonDict:
argument list.
Returns:
dict: If POST/PUT request then dictionary must be JSON serialisable,
If POST/PUT request then dictionary must be JSON serialisable,
otherwise must be appropriate for adding as query args.
"""
return {}
Expand Down
5 changes: 3 additions & 2 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,9 @@ class PushersRestServlet(RestServlet):
@user:server/pushers
Returns:
pushers: Dictionary containing pushers information.
total: Number of pushers in dictionary `pushers`.
A dictionary with keys:
pushers: Dictionary containing pushers information.
total: Number of pushers in dictionary `pushers`.
"""

PATTERNS = admin_patterns("/users/(?P<user_id>[^/]*)/pushers$")
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ async def _complete_login(
auth_provider_session_id: The session ID got during login from the SSO IdP.
Returns:
result: Dictionary of account information after successful login.
Dictionary of account information after successful login.
"""

# Before we actually log them in we check if they've already logged in
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/media/v1/thumbnailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def scale(self, width: int, height: int, output_type: str) -> BytesIO:
"""Rescales the image to the given dimensions.
Returns:
BytesIO: the bytes of the encoded image ready to be written to disk
The bytes of the encoded image ready to be written to disk
"""
with self._resize(width, height) as scaled:
return self._encode_image(scaled, output_type)
Expand All @@ -155,7 +155,7 @@ def crop(self, width: int, height: int, output_type: str) -> BytesIO:
max_height: The largest possible height.
Returns:
BytesIO: the bytes of the encoded image ready to be written to disk
The bytes of the encoded image ready to be written to disk
"""
if width * self.height > height * self.width:
scaled_width = width
Expand Down
12 changes: 7 additions & 5 deletions synapse/server_notices/resource_limits_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ async def _is_room_currently_blocked(self, room_id: str) -> Tuple[bool, List[str
room_id: The room id of the server notices room
Returns:
bool: Is the room currently blocked
list: The list of pinned event IDs that are unrelated to limit blocking
This list can be used as a convenience in the case where the block
is to be lifted and the remaining pinned event references need to be
preserved
Tuple of:
Is the room currently blocked
The list of pinned event IDs that are unrelated to limit blocking
This list can be used as a convenience in the case where the block
is to be lifted and the remaining pinned event references need to be
preserved
"""
currently_blocked = False
pinned_state_event = None
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def _get_device_updates_by_remote_txn(
limit: Maximum number of device updates to return
Returns:
List: List of device update tuples:
List of device update tuples:
- user_id
- device_id
- stream_id
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ async def get_room_complexity(self, room_id: str) -> Dict[str, float]:
room_id: The room ID to query.
Returns:
dict[str:float] of complexity version to complexity.
Map of complexity version to complexity.
"""
state_events = await self.get_current_state_event_counts(room_id)

Expand Down
7 changes: 4 additions & 3 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ async def get_event_report(self, report_id: int) -> Optional[Dict[str, Any]]:
Args:
report_id: ID of reported event in database
Returns:
event_report: json list of information from event report
json list of information from event report
"""

def _get_event_report_txn(
Expand Down Expand Up @@ -2130,8 +2130,9 @@ async def get_event_reports_paginate(
user_id: search for user_id. Ignored if user_id is None
room_id: search for room_id. Ignored if room_id is None
Returns:
event_reports: json list of event reports
count: total number of event reports matching the filter criteria
Tuple of:
json list of event reports
total number of event reports matching the filter criteria
"""

def _get_event_reports_paginate_txn(
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,10 @@ async def get_user_dir_rooms_user_is_in(self, user_id: str) -> List[str]:
Returns the rooms that a user is in.
Args:
user_id(str): Must be a local user
user_id: Must be a local user
Returns:
list: user_id
List of room IDs
"""
rows = await self.db_pool.simple_select_onecol(
table="users_who_share_private_rooms",
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/async_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async def concurrently_execute(
limit: Maximum number of conccurent executions.
Returns:
Deferred: Resolved when all function invocations have finished.
Resolved when all function invocations have finished.
"""
it = iter(args)

Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def register_cache(
resize_callback: A function which can be called to resize the cache.
Returns:
CacheMetric: an object which provides inc_{hits,misses,evictions} methods
an object which provides inc_{hits,misses,evictions} methods
"""
if resizable:
if not resize_callback:
Expand Down
9 changes: 5 additions & 4 deletions synapse/util/caches/dictionary_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ def get(
if it is in the cache.
Returns:
DictionaryEntry: If `dict_keys` is not None then `DictionaryEntry`
will contain include the keys that are in the cache. If None then
will either return the full dict if in the cache, or the empty
dict (with `full` set to False) if it isn't.
If `dict_keys` is not None then `DictionaryEntry` will contain include
the keys that are in the cache.
If None then will either return the full dict if in the cache, or the
empty dict (with `full` set to False) if it isn't.
"""
if dict_keys is None:
# The caller wants the full set of dictionary keys for this cache key
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/expiringcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def set_cache_factor(self, factor: float) -> bool:
items from the cache.
Returns:
bool: Whether the cache changed size or not.
Whether the cache changed size or not.
"""
new_size = int(self._original_max_size * factor)
if new_size != self._max_size:
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/lrucache.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def set_cache_factor(self, factor: float) -> bool:
items from the cache.
Returns:
bool: Whether the cache changed size or not.
Whether the cache changed size or not.
"""
if not self.apply_cache_factor_from_config:
return False
Expand Down
Loading

0 comments on commit a36e5a6

Please sign in to comment.