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

Commit

Permalink
Remove unused ignores due to mypy ParamSpec fixes
Browse files Browse the repository at this point in the history
python/mypy#12668

Cherry-picked from #13521
  • Loading branch information
David Robertson committed Sep 30, 2022
1 parent e51a202 commit bc73cb8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
4 changes: 1 addition & 3 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def register_sighup(func: Callable[P, None], *args: P.args, **kwargs: P.kwargs)
func: Function to be called when sent a SIGHUP signal.
*args, **kwargs: args and kwargs to be passed to the target function.
"""
# This type-ignore should be redundant once we use a mypy release with
# https://github.com/python/mypy/pull/12668.
_sighup_callbacks.append((func, args, kwargs)) # type: ignore[arg-type]
_sighup_callbacks.append((func, args, kwargs))


def start_worker_reactor(
Expand Down
4 changes: 2 additions & 2 deletions synapse/logging/opentracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,9 @@ def _wrapping_logic(
# FIXME: We could update this to handle any type of function by ignoring the
# first argument only if it's named `self` or `cls`. This isn't fool-proof
# but handles the idiomatic cases.
for i, arg in enumerate(args[1:], start=1): # type: ignore[index]
for i, arg in enumerate(args[1:], start=1):
set_tag(SynapseTags.FUNC_ARG_PREFIX + argspec.args[i], str(arg))
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :])) # type: ignore[index]
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :]))
set_tag(SynapseTags.FUNC_KWARGS, str(kwargs))
yield

Expand Down
22 changes: 6 additions & 16 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ def call_after(
# LoggingTransaction isn't expecting there to be any callbacks; assert that
# is not the case.
assert self.after_callbacks is not None
# type-ignore: need mypy containing https://github.com/python/mypy/pull/12668
self.after_callbacks.append((callback, args, kwargs)) # type: ignore[arg-type]
self.after_callbacks.append((callback, args, kwargs))

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

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

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

# Type-ignore Mypy doesn't yet consider ParamSpec.args to be iterable; see
# https://github.com/python/mypy/pull/12668
for i, arg in enumerate(args): # type: ignore[arg-type, var-annotated]
for i, arg in enumerate(args):
if inspect.isgenerator(arg):
logger.error(
"Programming error: generator passed to new_transaction as "
"argument %i to function %s",
i,
func,
)
# Type-ignore Mypy doesn't yet consider ParamSpec.args to be a mapping; see
# https://github.com/python/mypy/pull/12668
for name, val in kwargs.items(): # type: ignore[attr-defined]
for name, val in kwargs.items():
if inspect.isgenerator(val):
logger.error(
"Programming error: generator passed to new_transaction as "
Expand Down
4 changes: 1 addition & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ def looping_call(
*args: P.args,
**kwargs: P.kwargs,
) -> None:
# This type-ignore should be redundant once we use a mypy release with
# https://github.com/python/mypy/pull/12668.
self.loopers.append(Looper(function, interval / 1000.0, self.now, args, kwargs)) # type: ignore[arg-type]
self.loopers.append(Looper(function, interval / 1000.0, self.now, args, kwargs))

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

0 comments on commit bc73cb8

Please sign in to comment.