Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#575)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.4 → v0.8.0](astral-sh/ruff-pre-commit@v0.7.4...v0.8.0)

* Update for newer ruff

* Fix tests

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kevin Phoenix <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and twizmwazin authored Nov 25, 2024
1 parent 4d5cb00 commit 89283ad
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ repos:
- id: check-docstring-first

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.0
hooks:
- id: ruff
118 changes: 59 additions & 59 deletions claripy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,13 @@
__version__ = "9.2.130.dev0"

__all__ = (
"algorithm",
"Annotation",
"RegionAnnotation",
"SimplificationAvoidanceAnnotation",
"simplify",
"And",
"BoolS",
"BoolV",
"If",
"Not",
"Or",
"constraint_to_si",
"false",
"is_false",
"is_true",
"ite_cases",
"ite_dict",
"reverse_ite_cases",
"true",
"ast",
"BVS",
"BVV",
"ESI",
"FPS",
"FPV",
"FSORT_DOUBLE",
"FSORT_FLOAT",
"SGE",
"SGT",
"SI",
Expand All @@ -144,22 +128,60 @@
"ULE",
"ULT",
"VS",
"And",
"Annotation",
"BoolS",
"BoolV",
"ClaripyError",
"ClaripyFrontendError",
"ClaripyOperationError",
"ClaripySolverInterruptError",
"ClaripyZeroDivisionError",
"Concat",
"Extract",
"If",
"IntToStr",
"LShR",
"Not",
"Or",
"RegionAnnotation",
"Reverse",
"RotateLeft",
"RotateRight",
"SDiv",
"SignExt",
"SMod",
"SignExt",
"SimplificationAvoidanceAnnotation",
"Solver",
"SolverCacheless",
"SolverComposite",
"SolverConcrete",
"SolverHybrid",
"SolverReplacement",
"SolverStrings",
"SolverVSA",
"StrConcat",
"StrContains",
"StrIndexOf",
"StrIsDigit",
"StrLen",
"StrPrefixOf",
"StrReplace",
"StrSubstr",
"StrSuffixOf",
"StrToInt",
"StringS",
"StringV",
"UnsatError",
"ValueSet",
"ZeroExt",
"intersection",
"union",
"widen",
"FPS",
"FPV",
"algorithm",
"ast",
"backends",
"burrow_ite",
"constraint_to_si",
"excavate_ite",
"false",
"fpAbs",
"fpAdd",
"fpDiv",
Expand All @@ -180,39 +202,17 @@
"fpToIEEEBV",
"fpToSBV",
"fpToUBV",
"IntToStr",
"StrConcat",
"StrContains",
"StrIndexOf",
"StringS",
"StringV",
"StrIsDigit",
"StrLen",
"StrPrefixOf",
"StrReplace",
"StrSubstr",
"StrSuffixOf",
"StrToInt",
"set_debug",
"ClaripyError",
"ClaripyFrontendError",
"ClaripyOperationError",
"ClaripySolverInterruptError",
"ClaripyZeroDivisionError",
"UnsatError",
"FSORT_DOUBLE",
"FSORT_FLOAT",
"Solver",
"SolverCacheless",
"SolverComposite",
"SolverConcrete",
"SolverHybrid",
"SolverReplacement",
"SolverStrings",
"SolverVSA",
"burrow_ite",
"excavate_ite",
"backends",
"intersection",
"is_false",
"is_true",
"ite_cases",
"ite_dict",
"replace",
"replace_dict",
"reverse_ite_cases",
"set_debug",
"simplify",
"true",
"union",
"widen",
)
2 changes: 1 addition & 1 deletion claripy/ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .fp import FP
from .strings import String

__all__ = ("Bits", "BV", "FP", "Bool", "true", "false", "Base", "String")
__all__ = ("BV", "FP", "Base", "Bits", "Bool", "String", "false", "true")
30 changes: 15 additions & 15 deletions claripy/ast/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ReprLevel(IntEnum):

def _make_name(name: str, size: int, explicit_name: bool = False, prefix: str = "") -> str:
if not explicit_name:
return "%s%s_%d_%d" % (prefix, name, next(var_counter), size)
return f"{prefix}{name}_{next(var_counter)}_{size}"
return name


Expand Down Expand Up @@ -116,20 +116,20 @@ class Base:
_uninitialized: bool

__slots__ = [
"op",
"args",
"length",
"variables",
"symbolic",
"annotations",
"depth",
"__weakref__",
"_cached_encoded_name",
"_errored",
"_hash",
"_uneliminatable_annotations",
"_relocatable_annotations",
"_errored",
"_cached_encoded_name",
"_uneliminatable_annotations",
"_uninitialized",
"__weakref__",
"annotations",
"args",
"depth",
"length",
"op",
"symbolic",
"variables",
]

_hash_cache: WeakValueDictionary[int, Base] = WeakValueDictionary()
Expand Down Expand Up @@ -675,7 +675,7 @@ def shallow_repr(
]

prec_diff = parent_prec - op_prec
inner_infix_use_par = prec_diff < 0 or prec_diff == 0 and not left
inner_infix_use_par = prec_diff < 0 or (prec_diff == 0 and not left)
inner_repr = self._op_repr(op, args, inner, length, details, inner_infix_use_par)

if not inner:
Expand Down Expand Up @@ -705,7 +705,7 @@ def _op_repr(
value = format(args[0], "")
else:
value = format(args[0], "#x")
return value + "#%d" % length if length is not None else value
return f"{value}#{length}" if length is not None else value

if details < ReprLevel.MID_REPR:
if op == "If":
Expand Down Expand Up @@ -857,7 +857,7 @@ def canonicalize(self, var_map=None, counter=None) -> Self:

for v in self.leaf_asts():
if v.hash() not in var_map and v.is_leaf():
new_name = "canonical_%d" % next(counter)
new_name = f"canonical_{next(counter)}"
match v.op:
case "BVS":
var_map[v.hash()] = claripy.BVS(new_name, v.length, explicit_name=True)
Expand Down
8 changes: 4 additions & 4 deletions claripy/ast/bv.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def chop(self, bits=1):
"""
s = len(self)
if s % bits != 0:
raise ValueError("expression length (%d) should be a multiple of 'bits' (%d)" % (len(self), bits))
raise ValueError(f"expression length ({len(self)}) should be a multiple of 'bits' ({bits})")
if s == bits:
return [self]
return list(reversed([self[(n + 1) * bits - 1 : n * bits] for n in range(s // bits)]))
Expand Down Expand Up @@ -95,9 +95,7 @@ def get_bytes(self, index, size):
"""
pos = (self.size() + 7) // 8 - 1 - index
if pos < 0:
raise ValueError(
"Incorrect index %d. Your index must be between %d and %d." % (index, 0, self.size() // 8 - 1)
)
raise ValueError(f"Incorrect index {index}. Your index must be between 0 and {self.size() // 8 - 1}.")
if size == 0:
return BVV(0, 0)
r = self[min(pos * 8 + 7, self.size() - 1) : (pos - size + 1) * 8]
Expand Down Expand Up @@ -219,6 +217,8 @@ def BVS( # pylint:disable=redefined-builtin
name = name.decode()
if not isinstance(name, str):
raise TypeError(f"Name value for BVS must be a str, got {type(name)!r}")
if size is None or not isinstance(size, int):
raise TypeError("Size value for BVS must be an integer")

n = _make_name(name, size, False if explicit_name is None else explicit_name)
encoded_name = n.encode()
Expand Down
6 changes: 3 additions & 3 deletions claripy/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

__all__ = (
"Backend",
"BackendZ3",
"BackendConcrete",
"BackendVSA",
"BackendZ3",
"all_backends",
"any_backend",
"backends_by_type",
"concrete",
"z3",
"vsa",
"any_backend",
"z3",
)
6 changes: 3 additions & 3 deletions claripy/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class Backend:
# pylint: disable=too-many-positional-arguments

__slots__ = (
"_op_raw",
"_op_expr",
"_cache_objects",
"_false_cache",
"_op_expr",
"_op_raw",
"_solver_required",
"_tls",
"_true_cache",
"_false_cache",
)

def __init__(self, solver_required=None):
Expand Down
2 changes: 1 addition & 1 deletion claripy/backends/backend_concrete/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .fp import FPV
from .strings import StringV

__all__ = ("BackendConcrete", "BVV", "FPV", "StringV")
__all__ = ("BVV", "FPV", "BackendConcrete", "StringV")
8 changes: 4 additions & 4 deletions claripy/backends/backend_concrete/bv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def compare_guard(self, o):
raise ClaripyTypeError("The operation is not allowed on zero-length bitvectors.")

if self.bits != o.bits:
raise ClaripyTypeError("bitvectors are differently-sized (%d and %d)" % (self.bits, o.bits))
raise ClaripyTypeError(f"bitvectors are differently-sized ({self.bits} and {o.bits})")
return f(self, o)

return compare_guard
Expand All @@ -25,7 +25,7 @@ def compare_bits_0_length(f):
@functools.wraps(f)
def compare_guard(self, o):
if self.bits != o.bits:
raise ClaripyTypeError("bitvectors are differently-sized (%d and %d)" % (self.bits, o.bits))
raise ClaripyTypeError(f"bitvectors are differently-sized ({self.bits} and {o.bits})")
return f(self, o)

return compare_guard
Expand Down Expand Up @@ -53,7 +53,7 @@ class BVV(BackendObject):
Any use outside of claripy should use `claripy.BVV` instead.
"""

__slots__ = ["bits", "_value", "mod"]
__slots__ = ["_value", "bits", "mod"]

def __init__(self, value, bits):
if _d._DEBUG:
Expand Down Expand Up @@ -276,7 +276,7 @@ def size(self):
return self.bits

def __repr__(self):
return "BVV(0x%x, %d)" % (self.value, self.bits)
return f"BVV(0x{self.value:x}, {self.bits})"


#
Expand Down
8 changes: 4 additions & 4 deletions claripy/backends/backend_vsa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from .valueset import ValueSet

__all__ = (
"DEFAULT_MAX_CARDINALITY_WITHOUT_COLLAPSING",
"BackendVSA",
"Balancer",
"BoolResult",
"CreateStridedInterval",
"DiscreteStridedIntervalSet",
"FalseResult",
"MaybeResult",
"TrueResult",
"DEFAULT_MAX_CARDINALITY_WITHOUT_COLLAPSING",
"DiscreteStridedIntervalSet",
"CreateStridedInterval",
"StridedInterval",
"TrueResult",
"ValueSet",
)
10 changes: 4 additions & 6 deletions claripy/backends/backend_vsa/backend_vsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def normalize_arg_order(f):
@functools.wraps(f)
def normalizer(*args):
if len(args) != 2:
raise BackendError("Unsupported arguments number %d" % len(args))
raise BackendError(f"Unsupported arguments number {len(args)}")

if not isinstance(args[0], StridedInterval | DiscreteStridedIntervalSet | ValueSet):
if not isinstance(args[1], StridedInterval | DiscreteStridedIntervalSet | ValueSet):
Expand Down Expand Up @@ -423,7 +423,7 @@ def Reverse(arg):

def union(self, ast):
if len(ast.args) != 2:
raise BackendError("Incorrect number of arguments (%d) passed to BackendVSA.union()." % len(ast.args))
raise BackendError(f"Incorrect number of arguments ({len(ast.args)}) passed to BackendVSA.union().")

converted_0 = self.convert(ast.args[0])
converted_1 = self.convert(ast.args[1])
Expand All @@ -438,9 +438,7 @@ def union(self, ast):

def intersection(self, ast):
if len(ast.args) != 2:
raise BackendError(
"Incorrect number of arguments (%d) passed to BackendVSA.intersection()." % len(ast.args)
)
raise BackendError(f"Incorrect number of arguments ({len(ast.args)}) passed to BackendVSA.intersection().")

ret = None

Expand All @@ -451,7 +449,7 @@ def intersection(self, ast):

def widen(self, ast):
if len(ast.args) != 2:
raise BackendError("Incorrect number of arguments (%d) passed to BackendVSA.widen()." % len(ast.args))
raise BackendError(f"Incorrect number of arguments ({len(ast.args)}) passed to BackendVSA.widen().")

converted_0 = self.convert(ast.args[0])
converted_1 = self.convert(ast.args[1])
Expand Down
Loading

0 comments on commit 89283ad

Please sign in to comment.