Skip to content

Commit

Permalink
Revert "Add E lints"
Browse files Browse the repository at this point in the history
This reverts commit 6890333.
  • Loading branch information
twizmwazin committed Jun 20, 2024
1 parent 3d94c03 commit b39de24
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 35 deletions.
18 changes: 9 additions & 9 deletions claripy/ast/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from claripy.annotation import Annotation

try:
import _pickle as pickle
import cPickle as pickle
except ImportError:
import pickle

Expand Down Expand Up @@ -383,7 +383,7 @@ def _arg_serialize(arg) -> Optional[bytes]:
return b"\x1f"
elif arg is False:
return b"\x2e"
elif isinstance(arg, int):
elif type(arg) is int:
if arg < 0:
if arg >= -0x7FFF:
return b"-" + struct.pack("<h", arg)
Expand All @@ -400,11 +400,11 @@ def _arg_serialize(arg) -> Optional[bytes]:
elif arg <= 0xFFFF_FFFF_FFFF_FFFF:
return struct.pack("<Q", arg)
return None
elif isinstance(arg, str):
elif type(arg) is str:
return arg.encode()
elif isinstance(arg, float):
elif type(arg) is float:
return struct.pack("f", arg)
elif isinstance(arg, tuple):
elif type(arg) is tuple:
arr = []
for elem in arg:
b = Base._arg_serialize(elem)
Expand Down Expand Up @@ -505,7 +505,7 @@ def __a_init__(

def __hash__(self):
res = self._hash
if not isinstance(self._hash, int):
if type(self._hash) is not int:
res = hash(self._hash)
return res

Expand Down Expand Up @@ -755,13 +755,13 @@ def _op_repr(op, args, inner, length, details, inner_infix_use_par):
if op == "BVS":
extras = []
if args[1] is not None:
fmt = "%#x" if isinstance(args[1], int) else "%s"
fmt = "%#x" if type(args[1]) is int else "%s"
extras.append("min=%s" % (fmt % args[1]))
if args[2] is not None:
fmt = "%#x" if isinstance(args[2], int) else "%s"
fmt = "%#x" if type(args[2]) is int else "%s"
extras.append("max=%s" % (fmt % args[2]))
if args[3] is not None:
fmt = "%#x" if isinstance(args[3], int) else "%s"
fmt = "%#x" if type(args[3]) is int else "%s"
extras.append("stride=%s" % (fmt % args[3]))
if args[4] is True:
extras.append("UNINITIALIZED")
Expand Down
9 changes: 7 additions & 2 deletions claripy/ast/bool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import atexit
import logging

from claripy import operations
Expand All @@ -20,6 +19,8 @@ def cleanup():
del _boolv_cache


import atexit

atexit.register(cleanup)


Expand Down Expand Up @@ -78,6 +79,7 @@ def BoolV(val) -> Bool:
# Bound operations
#

from .. import operations

Bool.__eq__ = operations.op("__eq__", (Bool, Bool), Bool)
Bool.__ne__ = operations.op("__ne__", (Bool, Bool), Bool)
Expand Down Expand Up @@ -271,4 +273,7 @@ def constraint_to_si(expr):
return satisfiable, replace_list


from .bv import BVS # noqa: E402
from ..backend_manager import backends
from ..errors import ClaripyOperationError, ClaripyTypeError, BackendError
from .bits import Bits
from .bv import BVS
14 changes: 9 additions & 5 deletions claripy/ast/bv.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def BVS(
if stride == 0 and max != min:
raise ClaripyValueError("BVSes of stride 0 should have max == min")

if isinstance(name, bytes):
if type(name) is bytes:
name = name.decode()
if not isinstance(name, str):
raise TypeError(f"Name value for BVS must be a str, got {type(name)!r}")
Expand Down Expand Up @@ -276,20 +276,20 @@ def BVV(value, size=None, **kwargs) -> BV:
"""

if type(value) in (bytes, bytearray, memoryview, str):
if isinstance(value, str):
if type(value) is str:
l.warning("BVV value is a unicode string, encoding as utf-8")
value = value.encode("utf-8")

if size is None:
size = len(value) * 8
elif not isinstance(size, int):
elif type(size) is not int:
raise TypeError("Bitvector size must be either absent (implicit) or an integer")
elif size != len(value) * 8:
raise ClaripyValueError("string/size mismatch for BVV creation")

value = int.from_bytes(value, "big")

elif size is None or (not isinstance(value, int) and value is not None):
elif size is None or (type(value) is not int and value is not None):
raise TypeError("BVV() takes either an integer value and a size or a string of bytes")

# ensure the 0 <= value < (1 << size)
Expand Down Expand Up @@ -411,6 +411,8 @@ def DSIS(
# Unbound operations
#

from .bool import Bool
from .. import operations

# comparisons
ULT = operations.op("__lt__", (BV, BV), Bool, extra_check=operations.length_same_check, bound=False)
Expand Down Expand Up @@ -623,4 +625,6 @@ def DSIS(
"intersection", (BV, BV), BV, extra_check=operations.length_same_check, calc_length=operations.basic_length_calc
)

from . import fp # noqa: E402
from . import fp
from .. import vsa
from ..errors import ClaripyValueError
13 changes: 10 additions & 3 deletions claripy/ast/fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ def FPV(value, sort):
:param sort: The sort of the floating point.
:return: An FP AST.
"""
if isinstance(value, int):
if type(value) is int:
value = float(value)
elif not isinstance(value, float):
elif type(value) is float:
pass
else:
raise TypeError("Must instanciate FPV with a numerical value")

if not isinstance(sort, fp.FSort):
if type(sort) is not fp.FSort:
raise TypeError("Must instanciate FPV with a FSort")

if sort == FSORT_FLOAT:
Expand All @@ -122,6 +124,11 @@ def FPV(value, sort):
# unbound floating point conversions
#

from .. import operations
from .. import fp
from .bv import BV
from .bool import Bool


def _fp_length_calc(a1, a2, a3=None):
if isinstance(a1, fp.RM) and a3 is None:
Expand Down
14 changes: 14 additions & 0 deletions claripy/backends/backend_vsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,18 @@ def constraint_to_si(self, expr):
return Balancer(self, expr).compat_ret


from ..ast.base import Base
from ..operations import backend_operations_vsa_compliant, expression_set_operations
from ..vsa import (
StridedInterval,
CreateStridedInterval,
DiscreteStridedIntervalSet,
ValueSet,
AbstractLocation,
BoolResult,
TrueResult,
FalseResult,
)
from ..balancer import Balancer

BackendVSA.CreateStridedInterval = staticmethod(CreateStridedInterval)
11 changes: 11 additions & 0 deletions claripy/backends/backend_z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def popitem(self):
# And the (ugh) magic
#

from . import Backend

class BackendZ3(Backend):
_split_on = ("And", "Or")
Expand Down Expand Up @@ -1424,6 +1425,16 @@ def _op_raw_IntToStr(input_bv):
"Z3_OP_UNINTERPRETED": "UNINTERPRETED",
}

from ..ast.base import Base
from ..ast.bv import BV, BVV
from ..ast.bool import BoolV, Bool
from ..ast.strings import StringV
from ..ast.fp import FP, FPV
from ..operations import backend_operations, backend_fp_operations, backend_strings_operations
from ..fp import FSort, RM
from ..errors import ClaripyError, BackendError, ClaripyOperationError
from .. import _all_operations

op_type_map = {
# Boolean
"Z3_OP_TRUE": Bool,
Expand Down
5 changes: 4 additions & 1 deletion claripy/backends/backend_z3_parallel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import pickle
import threading
Expand All @@ -9,8 +8,12 @@

num_children = 0

import logging

l = logging.getLogger("claripy.backends.backend_z3_parallel")

from .backend_z3 import BackendZ3


class BackendZ3Parallel(BackendZ3):
def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions claripy/frontend.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

import logging
import numbers

from . import ast

l = logging.getLogger("claripy.frontends.frontend")


Expand Down
2 changes: 2 additions & 0 deletions claripy/frontend_mixins/constraint_expansion_mixin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import logging

from claripy.ast.bool import Or
Expand Down
10 changes: 10 additions & 0 deletions claripy/frontend_mixins/smtlib_script_dumper_mixin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import sys
import threading

from claripy.errors import BackendError, ClaripyFrontendError

Expand All @@ -20,3 +22,11 @@ def get_smtlib_script_satisfiability(self, extra_constraints=(), extra_variables
return self._solver_backend._get_satisfiability_smt_script(csts, variables)
except BackendError as e:
raise ClaripyFrontendError("Backend error during smtlib script generation") from e

# def merge(self, others, merge_conditions, common_ancestor=None):
# return self._solver_backend.__class__.__name__ == 'BackendZ3', ConstrainedFrontend.merge(
# self, others, merge_conditions, common_ancestor=common_ancestor
# )[1]


from ..errors import BackendError, ClaripyFrontendError
3 changes: 3 additions & 0 deletions claripy/frontends/composite_frontend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import itertools
import logging

l = logging.getLogger("claripy.frontends.composite_frontend")

import weakref
from typing import TYPE_CHECKING, Set

Expand Down
1 change: 1 addition & 0 deletions claripy/frontends/constrained_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

l = logging.getLogger("claripy.frontends.constrained_frontend")

from ..frontend import Frontend

class ConstrainedFrontend(Frontend): # pylint:disable=abstract-method
def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion claripy/frontends/hybrid_frontend.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python

import logging

from claripy.errors import ClaripyFrontendError
from claripy.frontend import Frontend

l = logging.getLogger("claripy.frontends.full_frontend")
_VALIDATE_BALANCER = False


Expand Down
1 change: 1 addition & 0 deletions claripy/frontends/light_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

l = logging.getLogger("claripy.frontends.light_frontend")

from .constrained_frontend import ConstrainedFrontend

class LightFrontend(ConstrainedFrontend):
def __init__(self, solver_backend, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions claripy/frontends/replacement_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

l = logging.getLogger("claripy.frontends.replacement_frontend")

from .constrained_frontend import ConstrainedFrontend

class ReplacementFrontend(ConstrainedFrontend):
def __init__(
Expand Down
5 changes: 5 additions & 0 deletions claripy/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,8 @@ def strtoint_bv_size_calc(s, bitlength): # pylint: disable=unused-argument
"Or",
"Xor",
}

from .errors import ClaripyOperationError, ClaripyTypeError
from . import simplifications
from . import ast
from . import fp
6 changes: 5 additions & 1 deletion claripy/simplifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ def rotate_shift_mask_simplifier(a, b):
return None
a_00, a_01 = a_0.args
a_10, a_11 = a_1.args
if a_00 is not a_10:
if not a_00 is a_10:
return None
if a_01.op != "BVV" or a_11.op != "BVV":
return None
Expand Down Expand Up @@ -1162,6 +1162,10 @@ def zeroext_comparing_against_simplifier(op, a, b):
"Or",
}

from .backend_manager import backends
from . import ast
from . import fp


# the actual instance
simpleton = SimplificationManager()
12 changes: 10 additions & 2 deletions claripy/vsa/strided_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

logger = logging.getLogger("claripy.vsa.strided_interval")

from ..backend_object import BackendObject


def reversed_processor(f):
def processor(self, *args, **kwargs):
Expand Down Expand Up @@ -3608,5 +3610,11 @@ def CreateStridedInterval(
return dsis


from . import discrete_strided_interval_set # noqa: E402
from .discrete_strided_interval_set import DiscreteStridedIntervalSet # noqa: E402
from .errors import ClaripyVSAError
from ..errors import ClaripyOperationError
from .bool_result import TrueResult, FalseResult, MaybeResult
from . import discrete_strided_interval_set
from .discrete_strided_interval_set import DiscreteStridedIntervalSet
from .valueset import ValueSet
from ..ast.base import Base
from ..bv import BVV
6 changes: 5 additions & 1 deletion claripy/vsa/valueset.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,8 @@ def identical(self, o):
return True


from .strided_interval import StridedInterval # noqa: E402
from ..ast.base import Base
from .strided_interval import StridedInterval
from .bool_result import BoolResult, TrueResult, FalseResult, MaybeResult
from .errors import ClaripyVSAOperationError, ClaripyVSAError
from ..errors import ClaripyValueError
5 changes: 3 additions & 2 deletions tests/test_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
def test_concrete():
a = claripy.BVV(10, 32)
b = claripy.BoolV(True)
# c = claripy.BVS('x', 32)

assert isinstance(claripy.backends.concrete.convert(a), claripy.bv.BVV)
assert isinstance(claripy.backends.concrete.convert(b), bool)
assert type(claripy.backends.concrete.convert(a)) is claripy.bv.BVV
assert type(claripy.backends.concrete.convert(b)) is bool

a = claripy.BVV(1337, 32)
b = a[31:16]
Expand Down
Loading

0 comments on commit b39de24

Please sign in to comment.