Fix up some typing errors.

This commit is contained in:
Mike Auty
2018-07-22 13:19:20 +01:00
parent 717aabf190
commit 4897b7ab81
8 changed files with 34 additions and 26 deletions
+5 -5
View File
@@ -162,14 +162,14 @@ class Module(interfaces.context.Module):
has_type = get_module_wrapper('has_type')
has_enum = get_module_wrapper('has_enum')
def get_symbols_by_absolute_location(self, offset: int, size: typing.Optional[int] = 0) -> typing.Iterable[str]:
def get_symbols_by_absolute_location(self, offset: int, size: int = 0) -> typing.List[str]:
"""Returns the symbols within this module that live at the specified absolute offset provided"""
if size < 0:
raise ValueError("Size must be strictly non-negative")
if offset > self._offset + self.size:
return []
return self._context.symbol_space.get_symbols_by_location(offset = offset - self._offset, size = size,
table_name = self.symbol_table_name)
return list(self._context.symbol_space.get_symbols_by_location(offset = offset - self._offset, size = size,
table_name = self.symbol_table_name))
class ModuleCollection(validity.ValidityRoutines):
@@ -186,7 +186,7 @@ class ModuleCollection(validity.ValidityRoutines):
All 0 sized modules will have identical hashes and are therefore included in the deduplicated version
"""
new_modules = []
seen = set()
seen = set() # type: typing.Set[str]
for mod in self._modules:
if mod.hash not in seen or mod.size == 0:
new_modules.append(mod)
@@ -207,7 +207,7 @@ class ModuleCollection(validity.ValidityRoutines):
result[module.name] = modlist
return result
def get_module_symbols_by_absolute_location(self, offset: int, size: typing.Optional[int] = 0) -> \
def get_module_symbols_by_absolute_location(self, offset: int, size: int = 0) -> \
typing.Iterable[typing.Tuple[str, typing.List[str]]]:
"""Returns a tuple of (module_name, list_of_symbol_names) for each module, where symbols live at the absolute offset in memory provided"""
if size < 0:
+2 -2
View File
@@ -219,8 +219,8 @@ class DataLayerInterface(configuration.ConfigurableInterface, validity.ValidityR
# Ensures we don't burn CPU cycles going round in a ready waiting loop
# without delaying the user too long between progress updates/results
result.wait(0.1)
for value in result.get():
yield from value
for result_value in result.get():
yield from result_value
else:
progress = DummyProgress()
scan_chunk = functools.partial(self._scan_chunk, scanner, min_address, max_address, progress)
+2 -2
View File
@@ -9,7 +9,7 @@ from abc import abstractmethod, ABCMeta
from volatility.framework import validity
Column = collections.namedtuple('Column', ['index', 'name', 'type'])
Column = typing.NamedTuple('Column', [('index', int), ('name', str), ('type', typing.Any)])
RenderOption = typing.Any
@@ -155,7 +155,7 @@ class TreeGrid(object, metaclass = ABCMeta):
@property
@abstractmethod
def columns(self) -> ColumnsType:
def columns(self) -> typing.List[Column]:
"""Returns the available columns and their ordering and types"""
@abstractmethod
+2 -2
View File
@@ -167,7 +167,7 @@ class BaseSymbolTableInterface(validity.ValidityRoutines):
symbol.type_name == type_name or (symbol.type_name.endswith(constants.BANG + type_name))):
yield symbol.name
def get_symbols_by_location(self, offset: int, size: typing.Optional[int] = 0) -> typing.Iterable[str]:
def get_symbols_by_location(self, offset: int, size: int = 0) -> typing.Iterable[str]:
"""Returns the name of all symbols in this table that live at a particular offset"""
if size < 0:
raise ValueError("Size must be strictly non-negative")
@@ -192,7 +192,7 @@ class SymbolSpaceInterface(collections.abc.Mapping):
@abstractmethod
def get_symbols_by_location(self,
offset: int,
size: typing.Optional[int] = 0,
size: int = 0,
table_name: typing.Optional[str] = None) -> typing.Iterable[str]:
"""Returns all symbols that exist at a specific relative address"""
+2 -2
View File
@@ -30,8 +30,8 @@ def pointer_to_string(pointer: objects.Pointer,
def array_of_pointers(array: interfaces.objects.ObjectInterface,
count: int,
subtype: typing.Optional[typing.Union[str, interfaces.objects.Template]] = None,
context: interfaces.context.ContextInterface = None) -> interfaces.objects.ObjectInterface:
subtype: typing.Union[str, interfaces.objects.Template],
context: interfaces.context.ContextInterface) -> interfaces.objects.ObjectInterface:
"""Takes an object, and recasts it as an array of pointers to subtype"""
symbol_table = array.vol.type_name.split(constants.BANG)[0]
if isinstance(subtype, str) and context is not None:
+15 -8
View File
@@ -197,16 +197,16 @@ class TreeGrid(interfaces.renderers.TreeGrid):
return self._populated
@property
def columns(self):
def columns(self) -> typing.List[interfaces.renderers.Column]:
"""Returns the available columns and their ordering and types"""
return self._columns
@property
def row_count(self):
def row_count(self) -> int:
"""Returns the number of rows populated"""
return self._row_count
def children(self, node):
def children(self, node) -> typing.List[interfaces.renderers.TreeNode]:
"""Returns the subnodes of a particular node in order"""
return [node for node, _ in self._find_children(node)]
@@ -290,7 +290,10 @@ class TreeGrid(interfaces.renderers.TreeGrid):
accumulator = function(node, initial_accumulator)
if children is not None:
if sort_key is not None:
children = sorted(children, key = lambda x: sort_key(x[0].values))
# FIXME: mypy #4973 or #2608
# key_func is only needed as a separate variable to pass mypy's None logic
key_func = lambda x: sort_key(x[0].values)
children = sorted(children, key = key_func)
if not sort_key.ascending:
children = reversed(children)
accumulator = self._visit(children, function, accumulator, sort_key)
@@ -306,7 +309,10 @@ class TreeGrid(interfaces.renderers.TreeGrid):
for n, children in list_of_children:
accumulator = function(n, accumulator)
if sort_key is not None:
children = sorted(children, key = lambda x: sort_key(x[0].values))
# FIXME: mypy #4973 or #2608
# key_func is only needed as a separate variable to pass mypy's None logic
key_func = lambda x: sort_key(x[0].values)
children = sorted(children, key = key_func)
if not sort_key.ascending:
children = reversed(children)
accumulator = self._visit(children, function, accumulator, sort_key)
@@ -315,15 +321,16 @@ class TreeGrid(interfaces.renderers.TreeGrid):
class ColumnSortKey(interfaces.renderers.ColumnSortKey):
def __init__(self, treegrid: TreeGrid, column_name: str, ascending: bool = True) -> None:
self._index = None
_index = None
self._type = None
self.ascending = ascending
for i in treegrid.columns:
if i.name.lower() == column_name.lower():
self._index = i.index
_index = i.index
self._type = i.type
if self._index is None:
if _index is None:
raise ValueError("Column not found in TreeGrid columns: {}".format(column_name))
self._index = _index
def __call__(self, values: typing.List[typing.Any]) -> typing.Any:
"""The key function passed as the sort key"""
+1 -2
View File
@@ -53,8 +53,7 @@ class SymbolSpace(interfaces.symbols.SymbolSpaceInterface, validity.ValidityRout
for symbol_name in self._dict[table].get_symbols_by_type(type_name):
yield table + constants.BANG + symbol_name
def get_symbols_by_location(self, offset: int, size: typing.Optional[int] = 0, table_name: str = None) -> \
typing.Iterable[str]:
def get_symbols_by_location(self, offset: int, size: int = 0, table_name: str = None) -> typing.Iterable[str]:
"""Returns all symbols that exist at a specific relative address"""
table_list = self._dict.values() # type: typing.Iterable[interfaces.symbols.BaseSymbolTableInterface]
if table_name is not None:
+5 -3
View File
@@ -30,10 +30,12 @@ class PsList(plugins.PluginInterface, timeliner.TimeLinerInterface):
@classmethod
def create_filter(cls, pid_list: typing.List[int] = None) -> typing.Callable[[int], bool]:
pid_list = pid_list or []
filter = lambda _: False
if [x for x in pid_list if x is not None]:
filter = lambda x: x not in pid_list
# FIXME: mypy #4973 or #2608
pid_list = pid_list or []
filter_list = [x for x in pid_list if x is not None]
if filter_list:
filter = lambda x: x not in filter_list
return filter
@classmethod