Skip to content

Commit

Permalink
mypy: debug.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 6, 2023
1 parent 78444f4 commit d00f1dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions coverage/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, options: Iterable[str]) -> None:

def get_output(self) -> str:
"""Get the output text from the `DebugControl`."""
return cast(str, self.raw_output.getvalue())
return cast(str, self.raw_output.getvalue()) # type: ignore


class NoDebugging:
Expand Down Expand Up @@ -188,9 +188,9 @@ def dump_stack_frames(
skip: int = 0
) -> None:
"""Print a summary of the stack to stdout, or someplace else."""
out = out or sys.stdout
out.write(short_stack(limit=limit, skip=skip+1))
out.write("\n")
fout = out or sys.stdout
fout.write(short_stack(limit=limit, skip=skip+1))
fout.write("\n")


def clipped_repr(text: str, numchars: int = 50) -> str:
Expand Down Expand Up @@ -371,17 +371,21 @@ def flush(self) -> None:
self.outfile.flush()


def log(msg: str, stack: bool = False) -> None: # pragma: debugging
def log(msg: str, stack: bool = False) -> None: # pragma: debugging
"""Write a log message as forcefully as possible."""
out = DebugOutputFile.get_one(interim=True)
out.write(msg+"\n")
if stack:
dump_stack_frames(out=out, skip=1)


def decorate_methods(decorator, butnot=(), private=False): # pragma: debugging
def decorate_methods(
decorator: Callable[..., Any],
butnot: Iterable[str] = (),
private: bool = False,
) -> Callable[..., Any]: # pragma: debugging
"""A class decorator to apply a decorator to methods."""
def _decorator(cls):
def _decorator(cls): # type: ignore
for name, meth in inspect.getmembers(cls, inspect.isroutine):
if name not in cls.__dict__:
continue
Expand All @@ -395,10 +399,10 @@ def _decorator(cls):
return _decorator


def break_in_pudb(func): # pragma: debugging
def break_in_pudb(func: Callable[..., Any]) -> Callable[..., Any]: # pragma: debugging
"""A function decorator to stop in the debugger for each call."""
@functools.wraps(func)
def _wrapper(*args, **kwargs):
def _wrapper(*args: Any, **kwargs: Any) -> Any:
import pudb
sys.stdout = sys.__stdout__
pudb.set_trace()
Expand All @@ -416,9 +420,9 @@ def show_calls(
show_return: bool = False,
) -> Callable[..., Any]: # pragma: debugging
"""A method decorator to debug-log each call to the function."""
def _decorator(func):
def _decorator(func: Callable[..., Any]) -> Callable[..., Any]:
@functools.wraps(func)
def _wrapper(self, *args, **kwargs):
def _wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
oid = getattr(self, OBJ_ID_ATTR, None)
if oid is None:
oid = f"{os.getpid():08d} {next(OBJ_IDS):04d}"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ setenv =
{[testenv]setenv}
C1=coverage/__init__.py coverage/__main__.py coverage/annotate.py coverage/bytecode.py
C2=coverage/cmdline.py coverage/collector.py coverage/config.py coverage/context.py coverage/control.py
C3=coverage/data.py coverage/disposition.py coverage/env.py coverage/exceptions.py
C3=coverage/data.py coverage/debug.py coverage/disposition.py coverage/env.py coverage/exceptions.py
C4=coverage/files.py coverage/inorout.py coverage/jsonreport.py coverage/lcovreport.py coverage/misc.py coverage/multiproc.py coverage/numbits.py
C5=coverage/parser.py coverage/phystokens.py coverage/plugin.py coverage/plugin_support.py coverage/python.py
C6=coverage/report.py coverage/results.py coverage/sqldata.py coverage/summary.py coverage/tomlconfig.py coverage/types.py coverage/version.py coverage/xmlreport.py
Expand Down

0 comments on commit d00f1dd

Please sign in to comment.