Skip to content

Commit

Permalink
Add more type annotations (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhelmot authored Sep 26, 2024
1 parent 4e6134a commit 06078d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions claripy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from claripy import ast
from claripy.annotation import Annotation, RegionAnnotation, SimplificationAvoidanceAnnotation
from claripy.ast.base import simplify
from claripy.ast.bool import (
Expand Down Expand Up @@ -129,6 +130,7 @@
"ite_dict",
"reverse_ite_cases",
"true",
"ast",
"BVS",
"BVV",
"ESI",
Expand Down
1 change: 1 addition & 0 deletions claripy/ast/bv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BV(Bits):
def intersection(self, other: BV) -> BV: ...
@property
def concrete_value(self) -> int: ...
def __hash__(self) -> int: ...

def BVS(
name: str,
Expand Down
18 changes: 9 additions & 9 deletions claripy/ast/fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FP(Bits):

__slots__ = ()

def to_fp(self, sort, rm=None):
def to_fp(self, sort, rm=None) -> FP:
"""
Convert this float to a different sort
Expand All @@ -37,13 +37,13 @@ def to_fp(self, sort, rm=None):

return fpToFP(rm, self, sort)

def raw_to_fp(self):
def raw_to_fp(self) -> FP:
"""
A counterpart to BV.raw_to_fp - does nothing and returns itself.
"""
return self

def raw_to_bv(self):
def raw_to_bv(self) -> BV:
"""
Interpret the bit-pattern of this IEEE754 floating point number as a bitvector.
The inverse of this function is to_bv.
Expand All @@ -52,10 +52,10 @@ def raw_to_bv(self):
"""
return fpToIEEEBV(self)

def to_bv(self):
def to_bv(self) -> BV:
return self.raw_to_bv()

def val_to_bv(self, size, signed=True, rm=None):
def val_to_bv(self, size, signed=True, rm=None) -> BV:
"""
Convert this floating point value to an integer.
Expand All @@ -71,18 +71,18 @@ def val_to_bv(self, size, signed=True, rm=None):
return op(rm, self, size)

@property
def sort(self):
def sort(self) -> FSort:
return FSort.from_size(self.length)

@staticmethod
def _from_float(like, value):
def _from_float(like, value) -> FP:
return FPV(float(value), like.sort)

_from_int = _from_float
_from_str = _from_float


def FPS(name, sort, explicit_name=None):
def FPS(name, sort, explicit_name=None) -> FP:
"""
Creates a floating-point symbol.
Expand All @@ -96,7 +96,7 @@ def FPS(name, sort, explicit_name=None):
return FP("FPS", (n, sort), variables=frozenset((n,)), symbolic=True, length=sort.length)


def FPV(value, sort):
def FPV(value, sort) -> FP:
"""
Creates a concrete floating-point value.
Expand Down

0 comments on commit 06078d5

Please sign in to comment.