Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use typeguard in CI testing; fix many typing issues #1655

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:

run_tests_from_dir() {
DIR=$1
pytest --durations=100 --cov=manticore -n auto "tests/$DIR"
pytest --typeguard-packages=manticore --durations=100 --cov=manticore -n auto "tests/$DIR"
coverage xml
}

Expand Down
31 changes: 15 additions & 16 deletions manticore/native/cpu/abstractcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
from capstone.x86 import X86_REG_ENDING
from capstone.arm import ARM_REG_ENDING

from typing import Any, Dict, List, Optional, Union
from typing import Any, Callable, Dict, Optional, Tuple

logger = logging.getLogger(__name__)
register_logger = logging.getLogger(f"{__name__}.registers")


def _sig_is_varargs(sig: inspect.Signature) -> bool:
VAR_POSITIONAL = inspect.Parameter.VAR_POSITIONAL
return any(p.kind == VAR_POSITIONAL for p in sig.parameters.values())


###################################################################################
# Exceptions

Expand Down Expand Up @@ -309,26 +315,21 @@ def values_from(self, base):
yield base
base += word_bytes

def get_argument_values(self, model, prefix_args):
def get_argument_values(self, model: Callable, prefix_args: Tuple) -> Tuple:
"""
Extract arguments for model from the environment and return as a tuple that
is ready to be passed to the model.

:param callable model: Python model of the function
:param tuple prefix_args: Parameters to pass to model before actual ones
:return: Arguments to be passed to the model
:rtype: tuple
"""
spec = inspect.getfullargspec(model)

if spec.varargs:
logger.warning("ABI: A vararg model must be a unary function.")
sig = inspect.signature(model)
if _sig_is_varargs(sig):
model_name = getattr(model, "__qualname__", "<no name>")
logger.warning("ABI: %s: a vararg model must be a unary function.", model_name)

nargs = len(spec.args) - len(prefix_args)

# If the model is a method, we need to account for `self`
if inspect.ismethod(model):
nargs -= 1
nargs = len(sig.parameters) - len(prefix_args)

def resolve_argument(arg):
if isinstance(arg, str):
Expand All @@ -343,11 +344,9 @@ def resolve_argument(arg):
from ..models import isvariadic # prevent circular imports

if isvariadic(model):
arguments = prefix_args + (argument_iter,)
return prefix_args + (argument_iter,)
else:
arguments = prefix_args + tuple(islice(argument_iter, nargs))

return arguments
return prefix_args + tuple(islice(argument_iter, nargs))

def invoke(self, model, prefix_args=None):
"""
Expand Down
Loading