Skip to content

Commit

Permalink
correct type hints for some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivas11789 committed Nov 7, 2019
1 parent 6920d24 commit 7e0fa0f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions manticore/core/smtlib/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,20 +682,24 @@ def cast(self, possible_array):
return arr
raise ValueError # cast not implemented

def cast_index(self, index: int) -> Union[int, "BitVecConstant"]:
def cast_index(self, index: Union[int, "BitVec"]) -> Union["BitVecConstant", "BitVec"]:
if isinstance(index, int):
# assert self.index_max is None or index >= 0 and index < self.index_max
return BitVecConstant(self.index_bits, index)
assert index.size == self.index_bits
return index

def cast_value(self, value: "BitVec") -> Union["BitVecConstant", "BitVec"]:
def cast_value(
self, value: Union["BitVec", str, bytes, int]
) -> Union["BitVecConstant", "BitVec"]:
if isinstance(value, BitVec):
assert value.size == self.value_bits
return value
if isinstance(value, (str, bytes)) and len(value) == 1:
value = ord(value)
if isinstance(value, int):
return BitVecConstant(self.value_bits, value)
assert value.size == self.value_bits
return value
if not isinstance(value, int):
value = int(value)
return BitVecConstant(self.value_bits, value)

def __len__(self):
if self.index_max is None:
Expand Down

0 comments on commit 7e0fa0f

Please sign in to comment.