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

Commit 6463244

Browse files
author
David Robertson
authored
Remove unused # type: ignores (#12531)
Over time we've begun to use newer versions of mypy, typeshed, stub packages---and of course we've improved our own annotations. This makes some type ignore comments no longer necessary. I have removed them. There was one exception: a module that imports `select.epoll`. The ignore is redundant on Linux, but I've kept it ignored for those of us who work on the source tree using not-Linux. (#11771) I'm more interested in the config line which enforces this. I want unused ignores to be reported, because I think it's useful feedback when annotating to know when you've fixed a problem you had to previously ignore. * Installing extras before typechecking Lacking an easy way to install all extras generically, let's bite the bullet and make install the hand-maintained `all` extra before typechecking. Now that matrix-org/backend-meta#6 is merged to the release/v1 branch.
1 parent 8a23bde commit 6463244

21 files changed

Lines changed: 60 additions & 57 deletions

File tree

.github/workflows/tests.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ jobs:
2020
- run: scripts-dev/config-lint.sh
2121

2222
lint:
23-
# This does a vanilla `poetry install` - no extras. I'm slightly anxious
24-
# that we might skip some typechecks on code that uses extras. However,
25-
# I think the right way to fix this is to mark any extras needed for
26-
# typechecking as development dependencies. To detect this, we ought to
27-
# turn up mypy's strictness: disallow unknown imports and be accept fewer
28-
# uses of `Any`.
2923
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
24+
with:
25+
typechecking-extras: "all"
3026

3127
lint-crlf:
3228
runs-on: ubuntu-latest

changelog.d/12531.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove unused `# type: ignore`s.

mypy.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ show_error_codes = True
77
show_traceback = True
88
mypy_path = stubs
99
warn_unreachable = True
10+
warn_unused_ignores = True
1011
local_partial_types = True
1112
no_implicit_optional = True
1213

@@ -134,6 +135,11 @@ disallow_untyped_defs = True
134135
[mypy-synapse.metrics.*]
135136
disallow_untyped_defs = True
136137

138+
[mypy-synapse.metrics._reactor_metrics]
139+
# This module imports select.epoll. That exists on Linux, but doesn't on macOS.
140+
# See https://github.com/matrix-org/synapse/pull/11771.
141+
warn_unused_ignores = False
142+
137143
[mypy-synapse.module_api.*]
138144
disallow_untyped_defs = True
139145

stubs/sortedcontainers/sorteddict.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ class SortedKeysView(KeysView[_KT_co], Sequence[_KT_co]):
115115
def __getitem__(self, index: slice) -> List[_KT_co]: ...
116116
def __delitem__(self, index: Union[int, slice]) -> None: ...
117117

118-
class SortedItemsView( # type: ignore
119-
ItemsView[_KT_co, _VT_co], Sequence[Tuple[_KT_co, _VT_co]]
120-
):
118+
class SortedItemsView(ItemsView[_KT_co, _VT_co], Sequence[Tuple[_KT_co, _VT_co]]):
121119
def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...
122120
@overload
123121
def __getitem__(self, index: int) -> Tuple[_KT_co, _VT_co]: ...

synapse/app/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from twisted.protocols.tls import TLSMemoryBIOFactory
4949
from twisted.python.threadpool import ThreadPool
5050

51-
import synapse
5251
from synapse.api.constants import MAX_PDU_SIZE
5352
from synapse.app import check_bind_error
5453
from synapse.app.phone_stats_home import start_phone_stats_home
@@ -60,6 +59,7 @@
6059
from synapse.events.third_party_rules import load_legacy_third_party_event_rules
6160
from synapse.handlers.auth import load_legacy_password_auth_providers
6261
from synapse.logging.context import PreserveLoggingContext
62+
from synapse.logging.opentracing import init_tracer
6363
from synapse.metrics import install_gc_manager, register_threadpool
6464
from synapse.metrics.background_process_metrics import wrap_as_background_process
6565
from synapse.metrics.jemalloc import setup_jemalloc_stats
@@ -431,7 +431,7 @@ def run_sighup(*args: Any, **kwargs: Any) -> None:
431431
refresh_certificate(hs)
432432

433433
# Start the tracer
434-
synapse.logging.opentracing.init_tracer(hs) # type: ignore[attr-defined] # noqa
434+
init_tracer(hs) # noqa
435435

436436
# Instantiate the modules so they can register their web resources to the module API
437437
# before we start the listeners.

synapse/config/server.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def generate_ip_set(
186186
class HttpResourceConfig:
187187
names: List[str] = attr.ib(
188188
factory=list,
189-
validator=attr.validators.deep_iterable(attr.validators.in_(KNOWN_RESOURCES)), # type: ignore
189+
validator=attr.validators.deep_iterable(attr.validators.in_(KNOWN_RESOURCES)),
190190
)
191191
compress: bool = attr.ib(
192192
default=False,
@@ -231,9 +231,7 @@ class ManholeConfig:
231231
class LimitRemoteRoomsConfig:
232232
enabled: bool = attr.ib(validator=attr.validators.instance_of(bool), default=False)
233233
complexity: Union[float, int] = attr.ib(
234-
validator=attr.validators.instance_of(
235-
(float, int) # type: ignore[arg-type] # noqa
236-
),
234+
validator=attr.validators.instance_of((float, int)), # noqa
237235
default=1.0,
238236
)
239237
complexity_error: str = attr.ib(

synapse/federation/federation_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ async def on_incoming_transaction(
268268
transaction_id=transaction_id,
269269
destination=destination,
270270
origin=origin,
271-
origin_server_ts=transaction_data.get("origin_server_ts"), # type: ignore
272-
pdus=transaction_data.get("pdus"), # type: ignore
271+
origin_server_ts=transaction_data.get("origin_server_ts"), # type: ignore[arg-type]
272+
pdus=transaction_data.get("pdus"),
273273
edus=transaction_data.get("edus"),
274274
)
275275

synapse/federation/transport/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,21 @@ async def send_transaction(
229229
"""
230230
logger.debug(
231231
"send_data dest=%s, txid=%s",
232-
transaction.destination, # type: ignore
233-
transaction.transaction_id, # type: ignore
232+
transaction.destination,
233+
transaction.transaction_id,
234234
)
235235

236-
if transaction.destination == self.server_name: # type: ignore
236+
if transaction.destination == self.server_name:
237237
raise RuntimeError("Transport layer cannot send to itself!")
238238

239239
# FIXME: This is only used by the tests. The actual json sent is
240240
# generated by the json_data_callback.
241241
json_data = transaction.get_dict()
242242

243-
path = _create_v1_path("/send/%s", transaction.transaction_id) # type: ignore
243+
path = _create_v1_path("/send/%s", transaction.transaction_id)
244244

245245
return await self.client.put_json(
246-
transaction.destination, # type: ignore
246+
transaction.destination,
247247
path=path,
248248
data=json_data,
249249
json_data_callback=json_data_callback,

synapse/handlers/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ async def check_ui_auth(
481481
sid = authdict["session"]
482482

483483
# Convert the URI and method to strings.
484-
uri = request.uri.decode("utf-8") # type: ignore
484+
uri = request.uri.decode("utf-8")
485485
method = request.method.decode("utf-8")
486486

487487
# If there's no session ID, create a new session.

synapse/handlers/oidc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ async def oidc_response_to_user_attributes(failures: int) -> UserAttributes:
966966
"Mapping provider does not support de-duplicating Matrix IDs"
967967
)
968968

969-
attributes = await self._user_mapping_provider.map_user_attributes( # type: ignore
969+
attributes = await self._user_mapping_provider.map_user_attributes(
970970
userinfo, token
971971
)
972972

0 commit comments

Comments
 (0)