From 7e519bb660cdfa45ac6c195964d39c1ef0b7a2f9 Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Fri, 6 Jan 2023 23:19:02 -0800 Subject: [PATCH] Fix some misc type errors (#1509) * Fix some misc type errors * Add missing return type hints --- pwndbg/commands/__init__.py | 12 ++++-------- pwndbg/commands/nearpc.py | 4 ++-- pwndbg/commands/slab.py | 16 ++++++++-------- pwndbg/gdblib/regs.py | 2 +- pyproject.toml | 1 - 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index 56d85d316..8bc7dbb48 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -233,7 +233,8 @@ def fix_int(*a, **kw): def fix_int_reraise(*a, **kw): - return fix(*a, reraise=True, **kw) + # Type error likely due to https://github.com/python/mypy/issues/6799 + return fix(*a, reraise=True, **kw) # type: ignore[misc] def OnlyWithFile(function): @@ -461,9 +462,6 @@ class _ArgparsedCommand(Command): parser, function, command_name=None, - is_alias=False, - aliases=[], - category=CommandCategory.MISC, *a, **kw, ) -> None: @@ -480,12 +478,10 @@ class _ArgparsedCommand(Command): # Note: function.__doc__ is used in the `pwndbg [filter]` command display function.__doc__ = self.parser.description.strip() - super(_ArgparsedCommand, self).__init__( + # Type error likely due to https://github.com/python/mypy/issues/6799 + super(_ArgparsedCommand, self).__init__( # type: ignore[misc] function, command_name=command_name, - is_alias=is_alias, - aliases=aliases, - category=category, *a, **kw, ) diff --git a/pwndbg/commands/nearpc.py b/pwndbg/commands/nearpc.py index 14bf84f5e..ff28cd5c1 100644 --- a/pwndbg/commands/nearpc.py +++ b/pwndbg/commands/nearpc.py @@ -22,7 +22,7 @@ parser.add_argument( @pwndbg.commands.ArgparsedCommand(parser, aliases=["pdisass", "u"], category=CommandCategory.DISASS) @pwndbg.commands.OnlyWhenRunning -def nearpc(pc=None, lines=None, emulate=False): +def nearpc(pc=None, lines=None, emulate=False) -> None: """ Disassemble near a specified address. """ @@ -44,7 +44,7 @@ parser.add_argument( @pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.DISASS) @pwndbg.commands.OnlyWhenRunning -def emulate(pc=None, lines=None, emulate_=True): +def emulate(pc=None, lines=None, emulate_=True) -> None: """ Like nearpc, but will emulate instructions from the current $PC forward. """ diff --git a/pwndbg/commands/slab.py b/pwndbg/commands/slab.py index 6cae2f816..715e1f465 100644 --- a/pwndbg/commands/slab.py +++ b/pwndbg/commands/slab.py @@ -96,17 +96,17 @@ def get_flags_list(flags: int): class IndentContextManager: - def __init__(self): + def __init__(self) -> None: self.indent = 0 - def __enter__(self): + def __enter__(self) -> None: self.indent += 1 - def __exit__(self, exc_type, exc_value, exc_tb): + def __exit__(self, exc_type, exc_value, exc_tb) -> None: self.indent -= 1 assert self.indent >= 0 - def print(self, *a, **kw): + def print(self, *a, **kw) -> None: print(" " * self.indent, *a, **kw) @@ -129,7 +129,7 @@ def _rx(val: int) -> str: def print_slab( slab: gdb.Value, freelist: Union[Iterator[int], List[int]], indent, verbose, is_partial -): +) -> None: page_address = int(slab.address) virt_address = pwndbg.gdblib.kernel.page_to_virt(page_address) indent.print(f"- {C.green('Slab')} @ {_yx(virt_address)} [{_rx(page_address)}]:") @@ -157,7 +157,7 @@ def print_slab( indent.print("-", _yx(int(entry))) -def print_cpu_cache(cpu_cache, offset, random, cpu_partial, indent, verbose): +def print_cpu_cache(cpu_cache, offset, random, cpu_partial, indent, verbose) -> None: address = int(cpu_cache) indent.print(f"{C.green('Per-CPU Data')} @ {_yx(address)}:") with indent: @@ -195,7 +195,7 @@ def print_cpu_cache(cpu_cache, offset, random, cpu_partial, indent, verbose): indent.print("Partial Slabs: (none)") -def slab_info(name: str, verbose: bool): +def slab_info(name: str, verbose: bool) -> None: cache = pwndbg.gdblib.kernel.slab.get_cache(name) if cache is None: @@ -231,7 +231,7 @@ def slab_info(name: str, verbose: bool): # TODO: print_node_cache -def slab_list(filter_): +def slab_list(filter_) -> None: results = [] for cache in pwndbg.gdblib.kernel.slab.caches(): name = cache["name"].string() diff --git a/pwndbg/gdblib/regs.py b/pwndbg/gdblib/regs.py index 854de616e..636b06e71 100644 --- a/pwndbg/gdblib/regs.py +++ b/pwndbg/gdblib/regs.py @@ -94,7 +94,7 @@ class module(ModuleType): return item - def __contains__(self, reg): + def __contains__(self, reg) -> bool: regs = set(reg_sets[pwndbg.gdblib.arch.current]) | {"pc", "sp"} return reg in regs diff --git a/pyproject.toml b/pyproject.toml index cf74d86e3..a6288e7ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ pretty = true show_error_codes = true incremental = false disable_error_code = [ - "misc", # Lots of dynamic attribute access "attr-defined", # https://github.com/python/mypy/issues/6232