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

Commit a3b35ee

Browse files
clokepH-Shay
authored andcommitted
Remove redundant types from comments. (#14412)
Remove type hints from comments which have been added as Python type hints. This helps avoid drift between comments and reality, as well as removing redundant information. Also adds some missing type hints which were simple to fill in.
1 parent 9b05118 commit a3b35ee

Some content is hidden

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

55 files changed

+174
-176
lines changed

changelog.d/14412.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove duplicated type information from type hints.

synapse/api/errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def to_synapse_error(self) -> SynapseError:
713713
set to the reason code from the HTTP response.
714714
715715
Returns:
716-
SynapseError:
716+
The error converted to a SynapseError.
717717
"""
718718
# try to parse the body as json, to get better errcode/msg, but
719719
# default to M_UNKNOWN with the HTTP status as the error text

synapse/config/logger.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,9 @@ def setup_logging(
317317
Set up the logging subsystem.
318318
319319
Args:
320-
config (LoggingConfig | synapse.config.worker.WorkerConfig):
321-
configuration data
320+
config: configuration data
322321
323-
use_worker_options (bool): True to use the 'worker_log_config' option
322+
use_worker_options: True to use the 'worker_log_config' option
324323
instead of 'log_config'.
325324
326325
logBeginner: The Twisted logBeginner to use.

synapse/crypto/keyring.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async def verify_json_for_server(
213213

214214
def verify_json_objects_for_server(
215215
self, server_and_json: Iterable[Tuple[str, dict, int]]
216-
) -> List[defer.Deferred]:
216+
) -> List["defer.Deferred[None]"]:
217217
"""Bulk verifies signatures of json objects, bulk fetching keys as
218218
necessary.
219219
@@ -226,10 +226,9 @@ def verify_json_objects_for_server(
226226
valid.
227227
228228
Returns:
229-
List<Deferred[None]>: for each input triplet, a deferred indicating success
230-
or failure to verify each json object's signature for the given
231-
server_name. The deferreds run their callbacks in the sentinel
232-
logcontext.
229+
For each input triplet, a deferred indicating success or failure to
230+
verify each json object's signature for the given server_name. The
231+
deferreds run their callbacks in the sentinel logcontext.
233232
"""
234233
return [
235234
run_in_background(

synapse/events/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,7 @@ def _event_type_from_format_version(
597597
format_version: The event format version
598598
599599
Returns:
600-
type: A type that can be initialized as per the initializer of
601-
`FrozenEvent`
600+
A type that can be initialized as per the initializer of `FrozenEvent`
602601
"""
603602

604603
if format_version == EventFormatVersions.ROOM_V1_V2:

synapse/federation/transport/client.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,11 @@ async def make_membership_event(
280280
Note that this does not append any events to any graphs.
281281
282282
Args:
283-
destination (str): address of remote homeserver
284-
room_id (str): room to join/leave
285-
user_id (str): user to be joined/left
286-
membership (str): one of join/leave
287-
params (dict[str, str|Iterable[str]]): Query parameters to include in the
288-
request.
283+
destination: address of remote homeserver
284+
room_id: room to join/leave
285+
user_id: user to be joined/left
286+
membership: one of join/leave
287+
params: Query parameters to include in the request.
289288
290289
Returns:
291290
Succeeds when we get a 2xx HTTP response. The result

synapse/federation/transport/server/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ class BaseFederationServlet:
224224
225225
With arguments:
226226
227-
origin (unicode|None): The authenticated server_name of the calling server,
227+
origin (str|None): The authenticated server_name of the calling server,
228228
unless REQUIRE_AUTH is set to False and authentication failed.
229229
230-
content (unicode|None): decoded json body of the request. None if the
230+
content (str|None): decoded json body of the request. None if the
231231
request was a GET.
232232
233233
query (dict[bytes, list[bytes]]): Query params from the request. url-decoded

synapse/handlers/e2e_keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ async def _process_self_signatures(
870870
- signatures of the user's master key by the user's devices.
871871
872872
Args:
873-
user_id (string): the user uploading the keys
873+
user_id: the user uploading the keys
874874
signatures (dict[string, dict]): map of devices to signed keys
875875
876876
Returns:

synapse/handlers/e2e_room_keys.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,9 @@ async def delete_version(self, user_id: str, version: Optional[str] = None) -> N
377377
"""Deletes a given version of the user's e2e_room_keys backup
378378
379379
Args:
380-
user_id(str): the user whose current backup version we're deleting
381-
version(str): the version id of the backup being deleted
380+
user_id: the user whose current backup version we're deleting
381+
version: Optional. the version ID of the backup version we're deleting
382+
If missing, we delete the current backup version info.
382383
Raises:
383384
NotFoundError: if this backup version doesn't exist
384385
"""

synapse/handlers/federation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,8 @@ async def get_room_complexity(
16141614
Fetch the complexity of a remote room over federation.
16151615
16161616
Args:
1617-
remote_room_hosts (list[str]): The remote servers to ask.
1618-
room_id (str): The room ID to ask about.
1617+
remote_room_hosts: The remote servers to ask.
1618+
room_id: The room ID to ask about.
16191619
16201620
Returns:
16211621
Dict contains the complexity

synapse/handlers/identity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ async def ask_id_server_for_third_party_invite(
711711
inviter_display_name: The current display name of the
712712
inviter.
713713
inviter_avatar_url: The URL of the inviter's avatar.
714-
id_access_token (str): The access token to authenticate to the identity
714+
id_access_token: The access token to authenticate to the identity
715715
server with
716716
717717
Returns:

synapse/handlers/oidc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ async def _fetch_userinfo(self, token: Token) -> UserInfo:
787787
Must include an ``access_token`` field.
788788
789789
Returns:
790-
UserInfo: an object representing the user.
790+
an object representing the user.
791791
"""
792792
logger.debug("Using the OAuth2 access_token to request userinfo")
793793
metadata = await self.load_metadata()

synapse/handlers/presence.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async def current_state_for_users(
201201
"""Get the current presence state for multiple users.
202202
203203
Returns:
204-
dict: `user_id` -> `UserPresenceState`
204+
A mapping of `user_id` -> `UserPresenceState`
205205
"""
206206
states = {}
207207
missing = []

synapse/handlers/saml.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def saml_response_to_user_attributes(
441441
client_redirect_url: where the client wants to redirect to
442442
443443
Returns:
444-
dict: A dict containing new user attributes. Possible keys:
444+
A dict containing new user attributes. Possible keys:
445445
* mxid_localpart (str): Required. The localpart of the user's mxid
446446
* displayname (str): The displayname of the user
447447
* emails (list[str]): Any emails for the user
@@ -483,7 +483,7 @@ def parse_config(config: dict) -> SamlConfig:
483483
Args:
484484
config: A dictionary containing configuration options for this provider
485485
Returns:
486-
SamlConfig: A custom config object for this module
486+
A custom config object for this module
487487
"""
488488
# Parse config options and use defaults where necessary
489489
mxid_source_attribute = config.get("mxid_source_attribute", "uid")

synapse/http/additional_resource.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def __init__(
4545
4646
Args:
4747
hs: homeserver
48-
handler ((twisted.web.server.Request) -> twisted.internet.defer.Deferred):
49-
function to be called to handle the request.
48+
handler: function to be called to handle the request.
5049
"""
5150
super().__init__()
5251
self._handler = handler

synapse/http/federation/matrix_federation_agent.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ def request(
155155
a file for a file upload). Or None if the request is to have
156156
no body.
157157
Returns:
158-
Deferred[twisted.web.iweb.IResponse]:
159-
fires when the header of the response has been received (regardless of the
160-
response status code). Fails if there is any problem which prevents that
161-
response from being received (including problems that prevent the request
162-
from being sent).
158+
A deferred which fires when the header of the response has been received
159+
(regardless of the response status code). Fails if there is any problem
160+
which prevents that response from being received (including problems that
161+
prevent the request from being sent).
163162
"""
164163
# We use urlparse as that will set `port` to None if there is no
165164
# explicit port.

synapse/http/matrixfederationclient.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,7 @@ async def post_json(
951951
952952
args: query params
953953
Returns:
954-
dict|list: Succeeds when we get a 2xx HTTP response. The
955-
result will be the decoded JSON body.
954+
Succeeds when we get a 2xx HTTP response. The result will be the decoded JSON body.
956955
957956
Raises:
958957
HttpResponseException: If we get an HTTP response code >= 300

synapse/http/proxyagent.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
)
3535
from twisted.web.error import SchemeNotSupported
3636
from twisted.web.http_headers import Headers
37-
from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS
37+
from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS, IResponse
3838

3939
from synapse.http import redact_uri
4040
from synapse.http.connectproxyclient import HTTPConnectProxyEndpoint, ProxyCredentials
@@ -134,7 +134,7 @@ def request(
134134
uri: bytes,
135135
headers: Optional[Headers] = None,
136136
bodyProducer: Optional[IBodyProducer] = None,
137-
) -> defer.Deferred:
137+
) -> "defer.Deferred[IResponse]":
138138
"""
139139
Issue a request to the server indicated by the given uri.
140140
@@ -157,17 +157,17 @@ def request(
157157
a file upload). Or, None if the request is to have no body.
158158
159159
Returns:
160-
Deferred[IResponse]: completes when the header of the response has
161-
been received (regardless of the response status code).
160+
A deferred which completes when the header of the response has
161+
been received (regardless of the response status code).
162162
163-
Can fail with:
164-
SchemeNotSupported: if the uri is not http or https
163+
Can fail with:
164+
SchemeNotSupported: if the uri is not http or https
165165
166-
twisted.internet.error.TimeoutError if the server we are connecting
167-
to (proxy or destination) does not accept a connection before
168-
connectTimeout.
166+
twisted.internet.error.TimeoutError if the server we are connecting
167+
to (proxy or destination) does not accept a connection before
168+
connectTimeout.
169169
170-
... other things too.
170+
... other things too.
171171
"""
172172
uri = uri.strip()
173173
if not _VALID_URI.match(uri):

synapse/http/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def register_paths(
267267
request. The first argument will be the request object and
268268
subsequent arguments will be any matched groups from the regex.
269269
This should return either tuple of (code, response), or None.
270-
servlet_classname (str): The name of the handler to be used in prometheus
270+
servlet_classname: The name of the handler to be used in prometheus
271271
and opentracing logs.
272272
"""
273273

synapse/http/site.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def _started_processing(self, servlet_name: str) -> None:
400400
be sure to call finished_processing.
401401
402402
Args:
403-
servlet_name (str): the name of the servlet which will be
403+
servlet_name: the name of the servlet which will be
404404
processing this request. This is used in the metrics.
405405
406406
It is possible to update this afterwards by updating

synapse/logging/context.py

+19-20
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ def __init__(self, copy_from: "Optional[ContextResourceUsage]" = None) -> None:
117117
"""Create a new ContextResourceUsage
118118
119119
Args:
120-
copy_from (ContextResourceUsage|None): if not None, an object to
121-
copy stats from
120+
copy_from: if not None, an object to copy stats from
122121
"""
123122
if copy_from is None:
124123
self.reset()
@@ -162,7 +161,7 @@ def __iadd__(self, other: "ContextResourceUsage") -> "ContextResourceUsage":
162161
"""Add another ContextResourceUsage's stats to this one's.
163162
164163
Args:
165-
other (ContextResourceUsage): the other resource usage object
164+
other: the other resource usage object
166165
"""
167166
self.ru_utime += other.ru_utime
168167
self.ru_stime += other.ru_stime
@@ -342,7 +341,7 @@ def current_context(cls) -> LoggingContextOrSentinel:
342341
called directly.
343342
344343
Returns:
345-
LoggingContext: the current logging context
344+
The current logging context
346345
"""
347346
warnings.warn(
348347
"synapse.logging.context.LoggingContext.current_context() is deprecated "
@@ -362,7 +361,8 @@ def set_current_context(
362361
called directly.
363362
364363
Args:
365-
context(LoggingContext): The context to activate.
364+
context: The context to activate.
365+
366366
Returns:
367367
The context that was previously active
368368
"""
@@ -474,8 +474,7 @@ def get_resource_usage(self) -> ContextResourceUsage:
474474
"""Get resources used by this logcontext so far.
475475
476476
Returns:
477-
ContextResourceUsage: a *copy* of the object tracking resource
478-
usage so far
477+
A *copy* of the object tracking resource usage so far
479478
"""
480479
# we always return a copy, for consistency
481480
res = self._resource_usage.copy()
@@ -663,7 +662,8 @@ def current_context() -> LoggingContextOrSentinel:
663662
def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSentinel:
664663
"""Set the current logging context in thread local storage
665664
Args:
666-
context(LoggingContext): The context to activate.
665+
context: The context to activate.
666+
667667
Returns:
668668
The context that was previously active
669669
"""
@@ -700,7 +700,7 @@ def nested_logging_context(suffix: str) -> LoggingContext:
700700
suffix: suffix to add to the parent context's 'name'.
701701
702702
Returns:
703-
LoggingContext: new logging context.
703+
A new logging context.
704704
"""
705705
curr_context = current_context()
706706
if not curr_context:
@@ -898,20 +898,19 @@ def defer_to_thread(
898898
on it.
899899
900900
Args:
901-
reactor (twisted.internet.base.ReactorBase): The reactor in whose main thread
902-
the Deferred will be invoked, and whose threadpool we should use for the
903-
function.
901+
reactor: The reactor in whose main thread the Deferred will be invoked,
902+
and whose threadpool we should use for the function.
904903
905904
Normally this will be hs.get_reactor().
906905
907-
f (callable): The function to call.
906+
f: The function to call.
908907
909908
args: positional arguments to pass to f.
910909
911910
kwargs: keyword arguments to pass to f.
912911
913912
Returns:
914-
Deferred: A Deferred which fires a callback with the result of `f`, or an
913+
A Deferred which fires a callback with the result of `f`, or an
915914
errback if `f` throws an exception.
916915
"""
917916
return defer_to_threadpool(reactor, reactor.getThreadPool(), f, *args, **kwargs)
@@ -939,20 +938,20 @@ def defer_to_threadpool(
939938
on it.
940939
941940
Args:
942-
reactor (twisted.internet.base.ReactorBase): The reactor in whose main thread
943-
the Deferred will be invoked. Normally this will be hs.get_reactor().
941+
reactor: The reactor in whose main thread the Deferred will be invoked.
942+
Normally this will be hs.get_reactor().
944943
945-
threadpool (twisted.python.threadpool.ThreadPool): The threadpool to use for
946-
running `f`. Normally this will be hs.get_reactor().getThreadPool().
944+
threadpool: The threadpool to use for running `f`. Normally this will be
945+
hs.get_reactor().getThreadPool().
947946
948-
f (callable): The function to call.
947+
f: The function to call.
949948
950949
args: positional arguments to pass to f.
951950
952951
kwargs: keyword arguments to pass to f.
953952
954953
Returns:
955-
Deferred: A Deferred which fires a callback with the result of `f`, or an
954+
A Deferred which fires a callback with the result of `f`, or an
956955
errback if `f` throws an exception.
957956
"""
958957
curr_context = current_context()

synapse/logging/opentracing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def inject_header_dict(
721721
destination: address of entity receiving the span context. Must be given unless
722722
check_destination is False. The context will only be injected if the
723723
destination matches the opentracing whitelist
724-
check_destination (bool): If false, destination will be ignored and the context
724+
check_destination: If false, destination will be ignored and the context
725725
will always be injected.
726726
727727
Note:
@@ -780,7 +780,7 @@ def get_active_span_text_map(destination: Optional[str] = None) -> Dict[str, str
780780
destination: the name of the remote server.
781781
782782
Returns:
783-
dict: the active span's context if opentracing is enabled, otherwise empty.
783+
the active span's context if opentracing is enabled, otherwise empty.
784784
"""
785785

786786
if destination and not whitelisted_homeserver(destination):

0 commit comments

Comments
 (0)