Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mypy from 1.5.1 to 1.8.0 #16901

Merged
merged 2 commits into from
Mar 13, 2024
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
57 changes: 29 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ async def check_auth(
# result is always the right type, but as it is 3rd party code it might not be

if not isinstance(result, tuple) or len(result) != 2:
logger.warning(
logger.warning( # type: ignore[unreachable]
"Wrong type returned by module API callback %s: %s, expected"
" Optional[Tuple[str, Optional[Callable]]]",
callback,
Expand Down Expand Up @@ -2248,7 +2248,7 @@ async def check_3pid_auth(
# result is always the right type, but as it is 3rd party code it might not be

if not isinstance(result, tuple) or len(result) != 2:
logger.warning(
logger.warning( # type: ignore[unreachable]
"Wrong type returned by module API callback %s: %s, expected"
" Optional[Tuple[str, Optional[Callable]]]",
callback,
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class UserAttributes:
display_name: Optional[str] = None
picture: Optional[str] = None
# mypy thinks these are incompatible for some reason.
emails: StrCollection = attr.Factory(list) # type: ignore[assignment]
emails: StrCollection = attr.Factory(list)


@attr.s(slots=True, auto_attribs=True)
Expand Down
6 changes: 1 addition & 5 deletions synapse/logging/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,7 @@ def run_in_background(
) -> "defer.Deferred[R]": ...


def run_in_background( # type: ignore[misc]
# The `type: ignore[misc]` above suppresses
# "Overloaded function implementation does not accept all possible arguments of signature 1"
# "Overloaded function implementation does not accept all possible arguments of signature 2"
# which seems like a bug in mypy.
def run_in_background(
f: Union[
Callable[P, R],
Callable[P, Awaitable[R]],
Expand Down
2 changes: 1 addition & 1 deletion synapse/module_api/callbacks/spamchecker_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ async def check_event_for_spam(
# mypy complains that we can't reach this code because of the
# return type in CHECK_EVENT_FOR_SPAM_CALLBACK, but we don't know
# for sure that the module actually returns it.
logger.warning(
logger.warning( # type: ignore[unreachable]
"Module returned invalid value, rejecting message as spam"
)
res = "This message has been rejected as probable spam"
Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,9 @@ async def _runInteraction() -> R:

try:
with opentracing.start_active_span(f"db.{desc}"):
result = await self.runWithConnection(
result: R = await self.runWithConnection(
# mypy seems to have an issue with this, maybe a bug?
self.new_transaction, # type: ignore[arg-type]
self.new_transaction,
desc,
after_callbacks,
async_after_callbacks,
Expand All @@ -934,7 +934,7 @@ async def _runInteraction() -> R:
await async_callback(*async_args, **async_kwargs)
for after_callback, after_args, after_kwargs in after_callbacks:
after_callback(*after_args, **after_kwargs)
return cast(R, result)
return result
except Exception:
for exception_callback, after_args, after_kwargs in exception_callbacks:
exception_callback(*after_args, **after_kwargs)
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ def get_all_new_backfill_event_rows(
# Type safety: iterating over `txn` yields `Tuple`, i.e.
# `Tuple[Any, ...]` of arbitrary length. Mypy detects assigning a
# variadic tuple to a fixed length tuple and flags it up as an error.
for row in txn: # type: ignore[assignment]
for row in txn:
new_event_updates.append((row[0], row[1:]))

limited = False
Expand All @@ -1903,7 +1903,7 @@ def get_all_new_backfill_event_rows(
# Type safety: iterating over `txn` yields `Tuple`, i.e.
# `Tuple[Any, ...]` of arbitrary length. Mypy detects assigning a
# variadic tuple to a fixed length tuple and flags it up as an error.
for row in txn: # type: ignore[assignment]
for row in txn:
new_event_updates.append((row[0], row[1:]))

if len(new_event_updates) >= limit:
Expand Down
9 changes: 5 additions & 4 deletions synapse/streams/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ def get_sources(self) -> Sequence[Tuple[StreamKeyType, EventSource]]:
class EventSources:
def __init__(self, hs: "HomeServer"):
self.sources = _EventSourcesInner(
# mypy previously warned that attribute.type is `Optional`, but we know it's
# attribute.type is `Optional`, but we know it's
# never `None` here since all the attributes of `_EventSourcesInner` are
# annotated.
# As of the stubs in attrs 22.1.0, `attr.fields()` now returns Any,
# so the call to `attribute.type` is not checked.
*(attribute.type(hs) for attribute in attr.fields(_EventSourcesInner))
*(
attribute.type(hs) # type: ignore[misc]
for attribute in attr.fields(_EventSourcesInner)
)
)
self.store = hs.get_datastores().main
self._instance_name = hs.get_instance_name()
Expand Down
12 changes: 2 additions & 10 deletions synapse/util/async_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,7 @@ async def yieldable_gather_results(
try:
return await make_deferred_yieldable(
defer.gatherResults(
# type-ignore: mypy reports two errors:
# error: Argument 1 to "run_in_background" has incompatible type
# "Callable[[T, **P], Awaitable[R]]"; expected
# "Callable[[T, **P], Awaitable[R]]" [arg-type]
# error: Argument 2 to "run_in_background" has incompatible type
# "T"; expected "[T, **P.args]" [arg-type]
# The former looks like a mypy bug, and the latter looks like a
# false positive.
[run_in_background(func, item, *args, **kwargs) for item in iter], # type: ignore[arg-type]
[run_in_background(func, item, *args, **kwargs) for item in iter],
consumeErrors=True,
)
)
Expand Down Expand Up @@ -338,7 +330,7 @@ async def yieldable_gather_results_delaying_cancellation(
return await make_deferred_yieldable(
delay_cancellation(
defer.gatherResults(
[run_in_background(func, item, *args, **kwargs) for item in iter], # type: ignore[arg-type]
[run_in_background(func, item, *args, **kwargs) for item in iter],
consumeErrors=True,
)
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/dictionary_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def get(
for dict_key in missing:
# We explicitly add each dict key to the cache, so that cache hit
# rates and LRU times for each key can be tracked separately.
value = entry.get(dict_key, _Sentinel.sentinel) # type: ignore[arg-type]
value = entry.get(dict_key, _Sentinel.sentinel)
self.cache[(key, dict_key)] = _PerKeyValue(value)

if value is not _Sentinel.sentinel:
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 @@ -142,7 +142,7 @@ def pop(self, key: KT, default: T = SENTINEL) -> Union[VT, T]:
return default

if self.iterable:
self.metrics.inc_evictions(EvictionReason.invalidation, len(value.value)) # type: ignore[arg-type]
self.metrics.inc_evictions(EvictionReason.invalidation, len(value.value))
else:
self.metrics.inc_evictions(EvictionReason.invalidation)

Expand Down
2 changes: 1 addition & 1 deletion tests/rest/client/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_add_filter_for_other_user(self) -> None:

def test_add_filter_non_local_user(self) -> None:
_is_mine = self.hs.is_mine
self.hs.is_mine = lambda target_user: False # type: ignore[method-assign]
self.hs.is_mine = lambda target_user: False # type: ignore[assignment]
channel = self.make_request(
"POST",
"/_matrix/client/r0/user/%s/filter" % (self.user_id),
Expand Down
Loading