Disallow any-generics (#2045)

pull/2047/head
Gulshan Singh 2 years ago committed by GitHub
parent 66df243bd6
commit 03f4dd0638
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,6 +3,8 @@ from __future__ import annotations
import os import os
import re import re
import sys import sys
from typing import Dict
from typing import Union
import gdb import gdb
@ -81,7 +83,7 @@ AT_CONSTANTS = {
sys.modules[__name__].__dict__.update({v: k for k, v in AT_CONSTANTS.items()}) sys.modules[__name__].__dict__.update({v: k for k, v in AT_CONSTANTS.items()})
class AUXV(dict): class AUXV(Dict[str, Union[int, str]]):
def set(self, const: int, value) -> None: def set(self, const: int, value) -> None:
name = AT_CONSTANTS.get(const, "AT_UNKNOWN%i" % const) name = AT_CONSTANTS.get(const, "AT_UNKNOWN%i" % const)

@ -567,7 +567,7 @@ class ArgparsedCommand:
if action.default is not None: if action.default is not None:
action.help += " (default: %(default)s)" action.help += " (default: %(default)s)"
def __call__(self, function: Callable) -> _ArgparsedCommand: def __call__(self, function: Callable[..., Any]) -> _ArgparsedCommand:
for alias in self.aliases: for alias in self.aliases:
_ArgparsedCommand( _ArgparsedCommand(
self.parser, function, command_name=alias, is_alias=True, category=self.category self.parser, function, command_name=alias, is_alias=True, category=self.category

@ -5,6 +5,7 @@ import ast
import os import os
import sys import sys
from collections import defaultdict from collections import defaultdict
from typing import Any
from typing import DefaultDict from typing import DefaultDict
from typing import List from typing import List
from typing import Tuple from typing import Tuple
@ -199,7 +200,7 @@ class CallOutput:
return False return False
def output(section): def output(section: str):
"""Creates a context manager corresponding to configured context output""" """Creates a context manager corresponding to configured context output"""
target = outputs.get(section, str(config_output)) target = outputs.get(section, str(config_output))
if not target or target == "stdout": if not target or target == "stdout":
@ -394,7 +395,7 @@ def context(subcontext=None) -> None:
sections += [(arg, context_sections.get(arg[0], None)) for arg in args] sections += [(arg, context_sections.get(arg[0], None)) for arg in args]
result = defaultdict(list) result = defaultdict(list)
result_settings: DefaultDict[str, dict] = defaultdict(dict) result_settings: DefaultDict[str, dict[Any, Any]] = defaultdict(dict)
for section, func in sections: for section, func in sections:
if func: if func:
target = output(section) target = output(section)

@ -20,7 +20,7 @@ Killing all other threads may be useful to use GDB checkpoints, e.g., to test gi
""", """,
) )
parser.add_argument("thread_ids", nargs="*", help="Thread IDs to kill.") parser.add_argument("thread_ids", type=int, nargs="*", help="Thread IDs to kill.")
parser.add_argument( parser.add_argument(
"-a", "-a",
"--all", "--all",
@ -31,7 +31,7 @@ parser.add_argument(
@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.PROCESS) @pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.PROCESS)
@pwndbg.commands.OnlyWhenRunning @pwndbg.commands.OnlyWhenRunning
def killthreads(thread_ids: list | None = None, all: bool = False) -> None: def killthreads(thread_ids: list[int] | None = None, all: bool = False) -> None:
if len(thread_ids) == 0 and not all: if len(thread_ids) == 0 and not all:
print(message.error("No thread IDs or --all flag specified")) print(message.error("No thread IDs or --all flag specified"))
return return

@ -65,7 +65,7 @@ VariableInstructionSizeMax = {
"rv64": 22, "rv64": 22,
} }
backward_cache: DefaultDict = collections.defaultdict(lambda: None) backward_cache: DefaultDict[int, int] = collections.defaultdict(lambda: None)
@pwndbg.lib.cache.cache_until("objfile") @pwndbg.lib.cache.cache_until("objfile")

@ -6,6 +6,7 @@ import os
import re import re
import subprocess import subprocess
from enum import Enum from enum import Enum
from typing import Any
import gdb import gdb
from tabulate import tabulate from tabulate import tabulate
@ -181,13 +182,13 @@ class Lambda:
self.deref_count -= 1 self.deref_count -= 1
return self return self
def evaluate(self, context: dict) -> int | Lambda: def evaluate(self, context: dict[Any, Any]) -> int | Lambda:
if self.deref_count > 0 or (self.obj and self.obj not in context): if self.deref_count > 0 or (self.obj and self.obj not in context):
raise ValueError(f"Can't eval {self}") raise ValueError(f"Can't eval {self}")
return context[self.obj] + self.immi return context[self.obj] + self.immi
@staticmethod @staticmethod
def parse(argument: str, predefined: dict = {}) -> int | Lambda: def parse(argument: str, predefined: dict[Any, Any] = {}) -> int | Lambda:
if not argument or argument == "!": if not argument or argument == "!":
return 0 return 0
try: try:

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import ctypes import ctypes
from typing import Any
import gdb import gdb
@ -202,7 +203,7 @@ class CStruct2GDB:
return fake_gdb_fields return fake_gdb_fields
@classmethod @classmethod
def keys(cls) -> list: def keys(cls) -> list[str]:
""" """
Return a list of the names of the fields in the struct to make it compatible with the `gdb.Type` interface. Return a list of the names of the fields in the struct to make it compatible with the `gdb.Type` interface.
""" """
@ -221,7 +222,7 @@ class CStruct2GDB:
""" """
return getattr(cls._c_struct, field).offset return getattr(cls._c_struct, field).offset
def items(self) -> tuple: def items(self) -> tuple[tuple[Any, Any], ...]:
""" """
Returns a tuple of (field name, field value) pairs. Returns a tuple of (field name, field value) pairs.
""" """

@ -481,7 +481,7 @@ class IDC:
def __init__(self) -> None: def __init__(self) -> None:
if available(): if available():
data: dict = _ida.eval(self.query) data: dict[Any, Any] = _ida.eval(self.query)
self.__dict__.update(data) self.__dict__.update(data)

@ -25,7 +25,7 @@ debug = NO_DEBUG
debug_name = "regs" debug_name = "regs"
class DebugCacheDict(UserDict): class DebugCacheDict(UserDict): # type: ignore[type-arg]
def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.hits = 0 self.hits = 0

@ -24,7 +24,7 @@ def config_to_key(name: str) -> str:
return "CONFIG_" + name.upper() return "CONFIG_" + name.upper()
class Kconfig(UserDict): class Kconfig(UserDict): # type: ignore[type-arg]
def __init__(self, compressed_config: bytes) -> None: def __init__(self, compressed_config: bytes) -> None:
super().__init__() super().__init__()
self.data = parse_compresed_config(compressed_config) self.data = parse_compresed_config(compressed_config)

@ -46,6 +46,7 @@ strict_optional = false
check_untyped_defs = true check_untyped_defs = true
allow_untyped_globals = true allow_untyped_globals = true
allow_redefinition = true allow_redefinition = true
allow_any_generics = false
warn_redundant_casts = true warn_redundant_casts = true
warn_unused_ignores = true warn_unused_ignores = true
warn_no_return = true warn_no_return = true

Loading…
Cancel
Save