From 36fd075836ed5d51751fe1b4b430f3828cf5c3e9 Mon Sep 17 00:00:00 2001 From: Nikhil Parasaram Date: Fri, 1 Feb 2019 17:54:48 +0530 Subject: [PATCH] Remove extra type definitions, add todo, use Baseclass over Union[SymbolicCalldata, ConcreteCalldata] --- mythril/laser/ethereum/strategy/basic.py | 2 +- mythril/laser/ethereum/transaction/transaction_models.py | 4 ++-- mythril/laser/smt/bool.py | 2 +- mythril/laser/smt/expression.py | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mythril/laser/ethereum/strategy/basic.py b/mythril/laser/ethereum/strategy/basic.py index 9e9eaf12..5930f4e6 100644 --- a/mythril/laser/ethereum/strategy/basic.py +++ b/mythril/laser/ethereum/strategy/basic.py @@ -14,7 +14,7 @@ except ImportError: from random import random from bisect import bisect - # Remove ignore after this has been fixed: https://github.com/python/mypy/issues/1297 + # TODO: Remove ignore after this has been fixed: https://github.com/python/mypy/issues/1297 def choices( # type: ignore population: List, weights: List[int] = None ) -> List[int]: diff --git a/mythril/laser/ethereum/transaction/transaction_models.py b/mythril/laser/ethereum/transaction/transaction_models.py index 6deefac3..05fc701f 100644 --- a/mythril/laser/ethereum/transaction/transaction_models.py +++ b/mythril/laser/ethereum/transaction/transaction_models.py @@ -87,10 +87,10 @@ class BaseTransaction: if call_data is None and init_call_data: self.call_data = SymbolicCalldata( self.id - ) # type: Union[SymbolicCalldata, ConcreteCalldata] + ) # type: BaseCalldata else: self.call_data = ( - cast(Union[SymbolicCalldata, ConcreteCalldata], call_data) + call_data if isinstance(call_data, BaseCalldata) else ConcreteCalldata(self.id, []) ) diff --git a/mythril/laser/smt/bool.py b/mythril/laser/smt/bool.py index aba401c3..9fa097e4 100644 --- a/mythril/laser/smt/bool.py +++ b/mythril/laser/smt/bool.py @@ -84,7 +84,7 @@ class Bool(Expression[z3.BoolRef]): def And(*args: Union[Bool, bool]) -> Bool: """Create an And expression.""" union = [] - args_list = [arg if isinstance(arg, Bool) else Bool(arg) for arg in args] # type: List[Bool] + args_list = [arg if isinstance(arg, Bool) else Bool(arg) for arg in args] for arg in args_list: union.append(arg.annotations) return Bool(z3.And([a.raw for a in args_list]), union) diff --git a/mythril/laser/smt/expression.py b/mythril/laser/smt/expression.py index 120e37e8..8e9e697e 100644 --- a/mythril/laser/smt/expression.py +++ b/mythril/laser/smt/expression.py @@ -46,7 +46,10 @@ class Expression(Generic[T]): return repr(self.raw) -def simplify(expression: T) -> T: +G = TypeVar("G", bound=Expression) + + +def simplify(expression: G) -> G: """Simplify the expression . :param expression: