From f1c5b3ca29d2dcff5af7410c844980dac91ea68b Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Thu, 11 Oct 2018 11:14:29 +0100 Subject: [PATCH] Improve the typing in places. --- volatility/framework/automagic/windows.py | 2 +- volatility/framework/layers/intel.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/volatility/framework/automagic/windows.py b/volatility/framework/automagic/windows.py index d3b7e5722..bc55bac4c 100644 --- a/volatility/framework/automagic/windows.py +++ b/volatility/framework/automagic/windows.py @@ -50,7 +50,7 @@ class DtbTest(validity.ValidityRoutines): self.ptr_size = struct.calcsize(ptr_struct) self.ptr_reference = self._check_type(ptr_reference, int) self.mask = self._check_type(mask, int) - self.page_size = layer_type.page_size + self.page_size = layer_type.page_size # type: int def _unpack(self, value: bytes) -> int: return struct.unpack("<" + self.ptr_struct, value)[0] diff --git a/volatility/framework/layers/intel.py b/volatility/framework/layers/intel.py index 7b8b06676..7353ef57a 100644 --- a/volatility/framework/layers/intel.py +++ b/volatility/framework/layers/intel.py @@ -9,16 +9,19 @@ from volatility.framework.configuration import requirements vollog = logging.getLogger(__name__) +_T = typing.TypeVar("_T") +_S = typing.TypeVar("_S") + class classproperty(object): """Class property decorator Note this will change the return type """ - def __init__(self, func: typing.Callable[[typing.Any], typing.Any]) -> None: + def __init__(self, func: typing.Callable[[_S], _T]) -> None: self._func = func - def __get__(self, _owner_self, owner_cls: typing.Type) -> typing.Any: + def __get__(self, _owner_self, owner_cls: _S) -> _T: return self._func(owner_cls) @@ -65,11 +68,11 @@ class Intel(interfaces.layers.TranslationLayerInterface): return cls._bits_per_register @classproperty - def minimum_address(cls) -> int: # type: ignore + def minimum_address(cls) -> int: return 0 @classproperty - def maximum_address(cls) -> int: # type: ignore + def maximum_address(cls) -> int: return (1 << cls._maxvirtaddr) - 1 @classproperty