Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ruff target version to Python 3.10 #405

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions claripy/ast/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import struct
import weakref
from collections import OrderedDict, deque
from collections.abc import Iterable, Iterator
from itertools import chain
from typing import TYPE_CHECKING, Generic, Iterable, Iterator, List, NoReturn, Optional, Tuple, TypeVar
from typing import TYPE_CHECKING, Generic, NoReturn, TypeVar

from claripy import operations, simplifications
from claripy.backend_manager import backends
Expand Down Expand Up @@ -376,7 +377,7 @@ def _calc_hash(op, args, keywords):
return md5_unpacker.unpack(hd)[0] # 64 bits

@staticmethod
def _arg_serialize(arg) -> Optional[bytes]:
def _arg_serialize(arg) -> bytes | None:
if arg is None:
return b"\x0f"
elif arg is True:
Expand Down Expand Up @@ -416,7 +417,7 @@ def _arg_serialize(arg) -> Optional[bytes]:
return None

@staticmethod
def _ast_serialize(op: str, args_tup, keywords) -> Optional[bytes]:
def _ast_serialize(op: str, args_tup, keywords) -> bytes | None:
"""
Serialize the AST and get a bytestring for hashing.

Expand Down Expand Up @@ -479,7 +480,7 @@ def __a_init__(
self.length = length
self.variables = frozenset(variables) if type(variables) is not frozenset else variables
self.symbolic = symbolic
self.annotations: Tuple[Annotation] = annotations
self.annotations: tuple[Annotation] = annotations
self._uneliminatable_annotations = uneliminatable_annotations
self._relocatable_annotations = relocatable_annotations

Expand Down Expand Up @@ -610,7 +611,7 @@ def append_annotation(self: T, a: "Annotation") -> T:
"""
return self._apply_to_annotations(lambda alist: (*alist, a))

def append_annotations(self: T, new_tuple: Tuple["Annotation", ...]) -> T:
def append_annotations(self: T, new_tuple: tuple["Annotation", ...]) -> T:
"""
Appends several annotations to this AST.

Expand All @@ -619,7 +620,7 @@ def append_annotations(self: T, new_tuple: Tuple["Annotation", ...]) -> T:
"""
return self._apply_to_annotations(lambda alist: alist + new_tuple)

def annotate(self: T, *args: "Annotation", remove_annotations: Optional[Iterable["Annotation"]] = None) -> T:
def annotate(self: T, *args: "Annotation", remove_annotations: Iterable["Annotation"] | None = None) -> T:
"""
Appends annotations to this AST.

Expand All @@ -643,7 +644,7 @@ def insert_annotation(self: T, a: "Annotation") -> T:
"""
return self._apply_to_annotations(lambda alist: (a, *alist))

def insert_annotations(self: T, new_tuple: Tuple["Annotation", ...]) -> T:
def insert_annotations(self: T, new_tuple: tuple["Annotation", ...]) -> T:
"""
Inserts several annotations to this AST.

Expand All @@ -652,7 +653,7 @@ def insert_annotations(self: T, new_tuple: Tuple["Annotation", ...]) -> T:
"""
return self._apply_to_annotations(lambda alist: new_tuple + alist)

def replace_annotations(self: T, new_tuple: Tuple["Annotation", ...]) -> T:
def replace_annotations(self: T, new_tuple: tuple["Annotation", ...]) -> T:
"""
Replaces annotations on this AST.

Expand Down Expand Up @@ -893,7 +894,7 @@ def swap_args(self: T, new_args, new_length=None, **kwargs) -> T:
# Other helper functions
#

def split(self, split_on: Iterable[str]) -> List:
def split(self, split_on: Iterable[str]) -> list:
"""
Splits the AST if its operation is `split_on` (i.e., return all the arguments). Otherwise, return a list with
just the AST.
Expand Down
4 changes: 1 addition & 3 deletions claripy/ast/strings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from claripy import operations
from claripy.ast.base import _make_name

Expand Down Expand Up @@ -150,7 +148,7 @@ def StringS(name, size, uninitialized=False, explicit_name=False, **kwargs):
return result


def StringV(value, length: Optional[int] = None, **kwargs):
def StringV(value, length: int | None = None, **kwargs):
"""
Create a new Concrete string (analogous to z3.StringVal())

Expand Down
6 changes: 3 additions & 3 deletions claripy/backends/backend_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _identical(self, a, b):
def _convert(self, a):
if type(a) in {int, str, bytes}:
return a
if isinstance(a, (numbers.Number, bv.BVV, fp.FPV, fp.RM, fp.FSort, strings.StringV)):
if isinstance(a, numbers.Number | bv.BVV | fp.FPV | fp.RM | fp.FSort | strings.StringV):
return a
raise BackendError(f"can't handle AST of type {type(a)}")

Expand Down Expand Up @@ -168,9 +168,9 @@ def _cardinality(self, b):

@staticmethod
def _to_primitive(expr):
if isinstance(expr, (bv.BVV, fp.FPV, strings.StringV)):
if isinstance(expr, bv.BVV | fp.FPV | strings.StringV):
return expr.value
elif isinstance(expr, (bool, numbers.Number)):
elif isinstance(expr, bool | numbers.Number):
return expr
else:
raise BackendError("idk how to turn this into a primitive")
Expand Down
6 changes: 3 additions & 3 deletions claripy/backends/backend_vsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _convert(self, a):
return a
elif isinstance(a, bool):
return TrueResult() if a else FalseResult()
if isinstance(a, (StridedInterval, DiscreteStridedIntervalSet, ValueSet)):
if isinstance(a, StridedInterval | DiscreteStridedIntervalSet | ValueSet):
return a
if isinstance(a, BoolResult):
return a
Expand All @@ -143,7 +143,7 @@ def _convert(self, a):
raise BackendError

def _eval(self, expr, n, extra_constraints=(), solver=None, model_callback=None):
if isinstance(expr, (StridedInterval, ValueSet)):
if isinstance(expr, StridedInterval | ValueSet):
return expr.eval(n)
elif isinstance(expr, BoolResult):
return expr.value
Expand Down Expand Up @@ -217,7 +217,7 @@ def _identical(self, a, b):
return a.identical(b)

def _unique(self, obj): # pylint:disable=unused-argument,no-self-use
if isinstance(obj, (StridedInterval, ValueSet)):
if isinstance(obj, StridedInterval | ValueSet):
return obj.unique
else:
raise BackendError(f"Not supported type of operand {type(obj)}")
Expand Down
4 changes: 2 additions & 2 deletions claripy/backends/backend_z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _convert(self, obj): # pylint:disable=arguments-renamed
return z3.BoolRef(z3.Z3_mk_true(self._context.ref()), self._context)
elif obj is False:
return z3.BoolRef(z3.Z3_mk_false(self._context.ref()), self._context)
elif isinstance(obj, (numbers.Number, str)) or (
elif isinstance(obj, numbers.Number | str) or (
hasattr(obj, "__module__") and obj.__module__ in ("z3", "z3.z3")
):
return obj
Expand Down Expand Up @@ -820,7 +820,7 @@ def _batch_eval(self, exprs, n, extra_constraints=(), solver=None, model_callbac
# construct results
r = []
for expr in exprs:
if not isinstance(expr, (numbers.Number, str, bool)):
if not isinstance(expr, numbers.Number | str | bool):
v = self._primitive_from_model(model, expr)
r.append(v)
else:
Expand Down
3 changes: 1 addition & 2 deletions claripy/balancer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import operator
from typing import Set

from . import _all_operations, vsa
from .ast.base import Base
Expand Down Expand Up @@ -320,7 +319,7 @@ def _get_assumptions(t):
# Truism extractor
#

def _unpack_truisms(self, c) -> Set:
def _unpack_truisms(self, c) -> set:
"""
Given a constraint, _unpack_truisms() returns a set of constraints that must be True for
this constraint to be True.
Expand Down
6 changes: 3 additions & 3 deletions claripy/frontend_mixins/constraint_fixer_mixin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, List, Set, Tuple, Union
from typing import TYPE_CHECKING, Union

from claripy import BoolV

Expand All @@ -7,8 +7,8 @@


class ConstraintFixerMixin:
def add(self, constraints: Union["Bool", List["Bool"], Set["Bool"], Tuple["Bool", ...]], **kwargs) -> List["Bool"]:
constraints = [constraints] if not isinstance(constraints, (list, tuple, set)) else constraints
def add(self, constraints: Union["Bool", list["Bool"], set["Bool"], tuple["Bool", ...]], **kwargs) -> list["Bool"]:
constraints = [constraints] if not isinstance(constraints, list | tuple | set) else constraints

if len(constraints) == 0:
return []
Expand Down
3 changes: 1 addition & 2 deletions claripy/frontend_mixins/model_cache_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import itertools
import weakref
from typing import Tuple

from claripy import backends, errors, false
from claripy.ast import Base, all_operations
Expand Down Expand Up @@ -102,7 +101,7 @@ def eval_constraints(self, constraints):
except errors.ClaripyZeroDivisionError:
return False

def eval_list(self, asts, allow_unconstrained: bool = True) -> Tuple:
def eval_list(self, asts, allow_unconstrained: bool = True) -> tuple:
"""
Evaluate a list of ASTs.

Expand Down
6 changes: 3 additions & 3 deletions claripy/frontends/composite_frontend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools
import logging
import weakref
from typing import TYPE_CHECKING, Set
from typing import TYPE_CHECKING

from claripy import backends
from claripy.ast import Base
Expand Down Expand Up @@ -113,7 +113,7 @@ def _solvers_for_variables(self, names):
return existing_solvers

@staticmethod
def _names_for(names=None, lst=None, lst2=None, e=None, v=None) -> Set[str]:
def _names_for(names=None, lst=None, lst2=None, e=None, v=None) -> set[str]:
if names is None:
names = set()
if e is not None and isinstance(e, Base):
Expand All @@ -133,7 +133,7 @@ def _names_for(names=None, lst=None, lst2=None, e=None, v=None) -> Set[str]:
def _merged_solver_for(self, *args, **kwargs):
return self._solver_for_names(self._names_for(*args, **kwargs))

def _solver_for_names(self, names: Set[str]) -> "SolverCompositeChild":
def _solver_for_names(self, names: set[str]) -> "SolverCompositeChild":
"""
Get a merged child solver for variables specified in `names`.

Expand Down
Loading
Loading