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

Commit 6d543d6

Browse files
David Robertsonclokep
andauthored
Update mypy and mypy-zope (#13925)
* Update mypy and mypy-zope * Unignore assigning to LogRecord attributes Presumably python/typeshed#8064 makes this ok Cherry-picked from #13521 * Remove unused ignores due to mypy ParamSpec fixes python/mypy#12668 Cherry-picked from #13521 * Remove additional unused ignores * Fix new mypy complaints related to `assertGreater` Presumably due to python/typeshed#8077 * Changelog * Reword changelog Co-authored-by: Patrick Cloke <[email protected]> Co-authored-by: Patrick Cloke <[email protected]>
1 parent b2aadd8 commit 6d543d6

File tree

10 files changed

+60
-67
lines changed

10 files changed

+60
-67
lines changed

changelog.d/13925.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update mypy (0.950 -> 0.981) and mypy-zope (0.3.7 -> 0.3.11).

poetry.lock

Lines changed: 30 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts-dev/check_pydantic_models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ def make_wrapper(factory: Callable[P, R]) -> Callable[P, R]:
8888

8989
@functools.wraps(factory)
9090
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
91-
# type-ignore: should be redundant once we can use https://github.com/python/mypy/pull/12668
92-
if "strict" not in kwargs: # type: ignore[attr-defined]
91+
if "strict" not in kwargs:
9392
raise MissingStrictInConstrainedTypeException(factory.__name__)
94-
if not kwargs["strict"]: # type: ignore[index]
93+
if not kwargs["strict"]:
9594
raise MissingStrictInConstrainedTypeException(factory.__name__)
9695
return factory(*args, **kwargs)
9796

synapse/app/_base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ def register_sighup(func: Callable[P, None], *args: P.args, **kwargs: P.kwargs)
9898
func: Function to be called when sent a SIGHUP signal.
9999
*args, **kwargs: args and kwargs to be passed to the target function.
100100
"""
101-
# This type-ignore should be redundant once we use a mypy release with
102-
# https://github.com/python/mypy/pull/12668.
103-
_sighup_callbacks.append((func, args, kwargs)) # type: ignore[arg-type]
101+
_sighup_callbacks.append((func, args, kwargs))
104102

105103

106104
def start_worker_reactor(

synapse/logging/context.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,29 +586,29 @@ def filter(self, record: logging.LogRecord) -> Literal[True]:
586586
True to include the record in the log output.
587587
"""
588588
context = current_context()
589-
record.request = self._default_request # type: ignore
589+
record.request = self._default_request
590590

591591
# context should never be None, but if it somehow ends up being, then
592592
# we end up in a death spiral of infinite loops, so let's check, for
593593
# robustness' sake.
594594
if context is not None:
595595
# Logging is interested in the request ID. Note that for backwards
596596
# compatibility this is stored as the "request" on the record.
597-
record.request = str(context) # type: ignore
597+
record.request = str(context)
598598

599599
# Add some data from the HTTP request.
600600
request = context.request
601601
if request is None:
602602
return True
603603

604-
record.ip_address = request.ip_address # type: ignore
605-
record.site_tag = request.site_tag # type: ignore
606-
record.requester = request.requester # type: ignore
607-
record.authenticated_entity = request.authenticated_entity # type: ignore
608-
record.method = request.method # type: ignore
609-
record.url = request.url # type: ignore
610-
record.protocol = request.protocol # type: ignore
611-
record.user_agent = request.user_agent # type: ignore
604+
record.ip_address = request.ip_address
605+
record.site_tag = request.site_tag
606+
record.requester = request.requester
607+
record.authenticated_entity = request.authenticated_entity
608+
record.method = request.method
609+
record.url = request.url
610+
record.protocol = request.protocol
611+
record.user_agent = request.user_agent
612612

613613
return True
614614

synapse/logging/opentracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,9 @@ def _wrapping_logic(
992992
# FIXME: We could update this to handle any type of function by ignoring the
993993
# first argument only if it's named `self` or `cls`. This isn't fool-proof
994994
# but handles the idiomatic cases.
995-
for i, arg in enumerate(args[1:], start=1): # type: ignore[index]
995+
for i, arg in enumerate(args[1:], start=1):
996996
set_tag(SynapseTags.FUNC_ARG_PREFIX + argspec.args[i], str(arg))
997-
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :])) # type: ignore[index]
997+
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :]))
998998
set_tag(SynapseTags.FUNC_KWARGS, str(kwargs))
999999
yield
10001000

synapse/storage/database.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ def call_after(
290290
# LoggingTransaction isn't expecting there to be any callbacks; assert that
291291
# is not the case.
292292
assert self.after_callbacks is not None
293-
# type-ignore: need mypy containing https://github.com/python/mypy/pull/12668
294-
self.after_callbacks.append((callback, args, kwargs)) # type: ignore[arg-type]
293+
self.after_callbacks.append((callback, args, kwargs))
295294

296295
def async_call_after(
297296
self, callback: Callable[P, Awaitable], *args: P.args, **kwargs: P.kwargs
@@ -312,8 +311,7 @@ def async_call_after(
312311
# LoggingTransaction isn't expecting there to be any callbacks; assert that
313312
# is not the case.
314313
assert self.async_after_callbacks is not None
315-
# type-ignore: need mypy containing https://github.com/python/mypy/pull/12668
316-
self.async_after_callbacks.append((callback, args, kwargs)) # type: ignore[arg-type]
314+
self.async_after_callbacks.append((callback, args, kwargs))
317315

318316
def call_on_exception(
319317
self, callback: Callable[P, object], *args: P.args, **kwargs: P.kwargs
@@ -331,8 +329,7 @@ def call_on_exception(
331329
# LoggingTransaction isn't expecting there to be any callbacks; assert that
332330
# is not the case.
333331
assert self.exception_callbacks is not None
334-
# type-ignore: need mypy containing https://github.com/python/mypy/pull/12668
335-
self.exception_callbacks.append((callback, args, kwargs)) # type: ignore[arg-type]
332+
self.exception_callbacks.append((callback, args, kwargs))
336333

337334
def fetchone(self) -> Optional[Tuple]:
338335
return self.txn.fetchone()
@@ -421,10 +418,7 @@ def _do_execute(
421418
sql = self.database_engine.convert_param_style(sql)
422419
if args:
423420
try:
424-
# The type-ignore should be redundant once mypy releases a version with
425-
# https://github.com/python/mypy/pull/12668. (`args` might be empty,
426-
# (but we'll catch the index error if so.)
427-
sql_logger.debug("[SQL values] {%s} %r", self.name, args[0]) # type: ignore[index]
421+
sql_logger.debug("[SQL values] {%s} %r", self.name, args[0])
428422
except Exception:
429423
# Don't let logging failures stop SQL from working
430424
pass
@@ -655,19 +649,15 @@ def new_transaction(
655649
# For now, we just log an error, and hope that it works on the first attempt.
656650
# TODO: raise an exception.
657651

658-
# Type-ignore Mypy doesn't yet consider ParamSpec.args to be iterable; see
659-
# https://github.com/python/mypy/pull/12668
660-
for i, arg in enumerate(args): # type: ignore[arg-type, var-annotated]
652+
for i, arg in enumerate(args):
661653
if inspect.isgenerator(arg):
662654
logger.error(
663655
"Programming error: generator passed to new_transaction as "
664656
"argument %i to function %s",
665657
i,
666658
func,
667659
)
668-
# Type-ignore Mypy doesn't yet consider ParamSpec.args to be a mapping; see
669-
# https://github.com/python/mypy/pull/12668
670-
for name, val in kwargs.items(): # type: ignore[attr-defined]
660+
for name, val in kwargs.items():
671661
if inspect.isgenerator(val):
672662
logger.error(
673663
"Programming error: generator passed to new_transaction as "

synapse/storage/databases/main/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ async def search_rooms(
641641
raise Exception("Unrecognized database engine")
642642

643643
# mypy expects to append only a `str`, not an `int`
644-
args.append(limit) # type: ignore[arg-type]
644+
args.append(limit)
645645

646646
results = await self.db_pool.execute(
647647
"search_rooms", self.db_pool.cursor_to_dict, sql, *args

tests/storage/test_monthly_active_users.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ def test_initialise_reserved_users(self):
9696

9797
# Test each of the registered users is marked as active
9898
timestamp = self.get_success(self.store.user_last_seen_monthly_active(user1))
99+
# Mypy notes that one shouldn't compare Optional[int] to 0 with assertGreater.
100+
# Check that timestamp really is an int.
101+
assert timestamp is not None
99102
self.assertGreater(timestamp, 0)
100103
timestamp = self.get_success(self.store.user_last_seen_monthly_active(user2))
104+
assert timestamp is not None
101105
self.assertGreater(timestamp, 0)
102106

103107
# Test that users with reserved 3pids are not removed from the MAU table
@@ -166,9 +170,11 @@ def test_user_last_seen_monthly_active(self):
166170
self.get_success(self.store.upsert_monthly_active_user(user_id2))
167171

168172
result = self.get_success(self.store.user_last_seen_monthly_active(user_id1))
173+
assert result is not None
169174
self.assertGreater(result, 0)
170175

171176
result = self.get_success(self.store.user_last_seen_monthly_active(user_id3))
177+
assert result is not None
172178
self.assertNotEqual(result, 0)
173179

174180
@override_config({"max_mau_value": 5})

tests/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ def looping_call(
270270
*args: P.args,
271271
**kwargs: P.kwargs,
272272
) -> None:
273-
# This type-ignore should be redundant once we use a mypy release with
274-
# https://github.com/python/mypy/pull/12668.
275-
self.loopers.append(Looper(function, interval / 1000.0, self.now, args, kwargs)) # type: ignore[arg-type]
273+
self.loopers.append(Looper(function, interval / 1000.0, self.now, args, kwargs))
276274

277275
def cancel_call_later(self, timer: Timer, ignore_errs: bool = False) -> None:
278276
if timer.expired:

0 commit comments

Comments
 (0)