Skip to content

Commit 5346eb0

Browse files
committed
switched over to ty
1 parent 9b36b20 commit 5346eb0

File tree

18 files changed

+97
-73
lines changed

18 files changed

+97
-73
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@ jobs:
6868
run: |
6969
uv run python -m pytest -m ""
7070
#KNUCKLE_SOLVER=cvc5 pytest
71-
- name: Run pyright
72-
uses: jakebailey/pyright-action@v2
71+
- name: Run ty
72+
run: |
73+
uvx ty check

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ classifiers = [
1212
"Topic :: Software Development :: Disassemblers",
1313

1414
]
15-
requires-python = ">= 3.11"
15+
requires-python = ">= 3.12"
1616
dependencies = [
1717
"z3-solver >= 4.15.4",
1818
"lark>=1.3.1",
@@ -116,7 +116,6 @@ dev = [
116116
"jupyter>=1.1.1",
117117
"line-profiler>=5.0.0",
118118
"nbclient>=0.10.2",
119-
"pyright>=1.1.392.post0",
120119
"pytest>=8.3.4",
121120
"ruff>=0.11.13",
122121
]

src/kdrag/contrib/pcode/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def getRegisterName(self) -> str:
111111

112112
# Varnode by default has pointer identity. This makes dictionaries not work correctly.
113113

114-
pypcode.Varnode.__hash__ = lambda self: hash((self.space.name, self.offset, self.size))
114+
pypcode.Varnode.__hash__ = lambda self: hash((self.space.name, self.offset, self.size)) # type: ignore[assignment]
115115

116116

117117
def varnode_eq(self: pypcode.Varnode, other) -> bool:
@@ -123,7 +123,7 @@ def varnode_eq(self: pypcode.Varnode, other) -> bool:
123123
)
124124

125125

126-
pypcode.Varnode.__eq__ = varnode_eq
126+
pypcode.Varnode.__eq__ = varnode_eq # type: ignore[assignment]
127127

128128

129129
class CachedArray(NamedTuple):
@@ -726,7 +726,10 @@ def sym_execute(
726726
max_insns1 = max_insns
727727
memstate2 = memstate1
728728
next_pc = (addr, pcode_pc)
729-
path_cond1 = path_cond + [pc1[0] == vaddr, pc1[1] == vpcode_pc]
729+
path_cond1 = path_cond + [
730+
smt.Eq(pc1[0], vaddr),
731+
smt.Eq(pc1[1], vpcode_pc),
732+
]
730733
if addr in breakpoints:
731734
res.append(SimState(memstate2, next_pc, path_cond1))
732735
elif max_insns1 <= 0:

src/kdrag/datatype.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,10 @@ def Struct(
375375
>>> kd.QForAll([p], p.x > -42)
376376
ForAll(p, Implies(And(x(p) > 0, y(p) > 0), x(p) > -42))
377377
"""
378-
rec = Inductive(name)
379-
rec.declare(name, *fields)
380-
rec = rec.create()
378+
rec0 = Inductive(name)
379+
rec0.declare(name, *fields)
380+
rec = rec0.create()
381+
assert isinstance(rec, smt.DatatypeSortRef)
381382
rec.mk = rec.constructor(0)
382383
wf_cond = [
383384
n for (n, (_, sort)) in enumerate(fields) if sort in kd.notation.wf.methods
@@ -461,7 +462,7 @@ def declare(
461462
olddeclare(name, *args)
462463
preds.append(pred)
463464

464-
dt.declare = declare
465+
dt.declare = declare # type: ignore[assignment]
465466

466467
oldcreate = dt.create
467468

@@ -505,7 +506,7 @@ def create():
505506
kd.notation.wf.register(dt, lambda x: x.rel())
506507
return dt
507508

508-
dt.create = create
509+
dt.create = create # type: ignore[assignment]
509510
return dt
510511

511512

src/kdrag/kernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def subst(t: smt.ExprRef, eqs: Sequence[Proof]) -> tuple[smt.ExprRef, Proof]:
377377
assert all(isinstance(eq, kd.Proof) and smt.is_eq(eq.thm) for eq in eqs)
378378
subst = [(eq.thm.arg(0), eq.thm.arg(1)) for eq in eqs]
379379
t1 = smt.substitute(t, *subst)
380-
return t1, kd.axiom(t == t1, ["subst", t, eqs])
380+
return t1, kd.axiom(smt.Eq(t, t1), ["subst", t, eqs])
381381

382382

383383
def instan(ts: Sequence[smt.ExprRef], pf: Proof) -> Proof:
@@ -653,8 +653,8 @@ def declare(name, *args):
653653
],
654654
)
655655

656-
dt.create = create
657-
dt.declare = declare
656+
dt.create = create # type: ignore[assignment]
657+
dt.declare = declare # type: ignore[assignment]
658658
return dt
659659

660660

src/kdrag/modal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,6 @@ def In(x: PExprRef, S: smt.FuncRef, prefix="t") -> PBoolRef:
209209
"""
210210
doms = smt.domains(S)
211211
vs = [smt.FreshConst(d, prefix=prefix) for n, d in enumerate(doms)]
212-
return smt.Lambda(vs, S[*vs][x(*vs)])
212+
S1 = S(*vs)
213+
assert isinstance(S1, smt.QuantifierRef) or isinstance(S1, smt.ArrayRef)
214+
return smt.Lambda(vs, S1[x(*vs)])

src/kdrag/notation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import kdrag as kd
2020

2121

22-
smt.SortRef.__rshift__ = lambda self, other: smt.ArraySort(self, other) # type: ignore
22+
smt.SortRef.__rshift__ = lambda self, other: smt.ArraySort(self, other) # type: ignore[assignment]
2323

24-
smt.ArrayRef.__call__ = lambda self, *arg: self[arg]
24+
smt.ArrayRef.__call__ = lambda self, *arg: self[arg] # type: ignore[assignment]
2525

2626

2727
def compose(f: smt.FuncDeclRef, g: smt.FuncDeclRef) -> smt.FuncDeclRef:
@@ -57,7 +57,7 @@ def quantifier_call(self, *args):
5757
)
5858

5959

60-
smt.QuantifierRef.__call__ = quantifier_call
60+
smt.QuantifierRef.__call__ = quantifier_call # type: ignore[assignment]
6161

6262

6363
class SortDispatch:

src/kdrag/parsers/microlean.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import kdrag.smt as smt
1414
from lark import Tree
1515
import kdrag as kd
16-
from typing import NamedTuple, Optional
16+
from typing import Optional
17+
from dataclasses import dataclass
1718

1819

1920
# TODO: let syntax
@@ -90,7 +91,8 @@
9091
)
9192

9293

93-
class Env(NamedTuple):
94+
@dataclass
95+
class Env:
9496
locals: dict
9597
globals: dict
9698

src/kdrag/parsers/tptp.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@ def tff_typed_variable(self, items):
308308
cast(str | list[Any] | tuple[str, Any, Any], items[1])
309309
)
310310
if isinstance(sort, tuple):
311-
sort = self._function_sort_from_sig(sort) if self.thf_mode else self.sort
311+
sort = (
312+
self._function_sort_from_sig(
313+
cast(tuple[list[smt.SortRef], Optional[smt.SortRef]], sort)
314+
)
315+
if self.thf_mode
316+
else self.sort
317+
)
312318
if sort is None:
313319
sort = self.sort
314320
v = smt.Const(name, sort)
@@ -408,15 +414,17 @@ def _declare_symbol(
408414
if isinstance(type_repr, tuple) and type_repr[0] == "fun":
409415
sig = self._type_repr_to_sort(type_repr)
410416
assert isinstance(sig, tuple)
411-
doms, rng = sig
417+
doms, rng = cast(tuple[list[smt.SortRef], Optional[smt.SortRef]], sig)
412418
doms = list(doms)
413419
rng = rng if rng is not None else self.sort
414420
self.func_sigs[name] = (doms, rng)
415421
if not self.thf_mode:
416422
fn = smt.Function(name, *doms, rng)
417423
self.funcs[(name, len(doms))] = fn
418424
return fn
419-
sort = self._function_sort_from_sig((doms, rng))
425+
sort = self._function_sort_from_sig(
426+
cast(tuple[list[smt.SortRef], Optional[smt.SortRef]], (doms, rng))
427+
)
420428
const = smt.Const(name, sort)
421429
self.consts[name] = const
422430
return const
@@ -451,17 +459,14 @@ def _type_repr_to_sort(
451459
rng_sort = self._type_repr_to_sort(rng)
452460
if isinstance(rng_sort, tuple):
453461
rng_doms, rng_rng = rng_sort
454-
dom_sorts.extend(rng_doms)
462+
dom_sorts.extend(cast(list[smt.SortRef], rng_doms)) # type: ignore
455463
rng_sort = rng_rng
456464
return (
457465
cast(list[smt.SortRef], dom_sorts),
458466
cast(Optional[smt.SortRef], rng_sort),
459467
)
460468
if isinstance(type_repr, list):
461-
return [
462-
cast(smt.SortRef, self._type_repr_to_sort(cast(Any, t)))
463-
for t in type_repr
464-
]
469+
return [cast(smt.SortRef, self._type_repr_to_sort(t)) for t in type_repr]
465470
if isinstance(type_repr, str):
466471
if type_repr == "$o":
467472
return smt.BoolSort()

src/kdrag/reflect.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def type_of_sort(s: smt.SortRef) -> type:
7373
>>> type_of_sort(smt.IntSort())
7474
<class 'int'>
7575
>>> type_of_sort(smt.ArraySort(smt.StringSort(), smt.IntSort()))
76-
dict[str, int]
76+
<class 'dict'>
7777
>>> type_of_sort(smt.SeqSort(smt.IntSort()))
78-
list[int]
78+
<class 'list'>
7979
"""
8080
if s == smt.IntSort():
8181
return int
@@ -86,9 +86,9 @@ def type_of_sort(s: smt.SortRef) -> type:
8686
elif s == smt.StringSort():
8787
return str
8888
elif isinstance(s, smt.ArraySortRef):
89-
return dict[type_of_sort(s.domain()), type_of_sort(s.range())]
89+
return dict # type_of_sort(s.domain()), type_of_sort(s.range())]
9090
elif isinstance(s, smt.SeqSortRef):
91-
return list[type_of_sort(s.basis())]
91+
return list # [type_of_sort(s.basis())]
9292
else:
9393
raise NotImplementedError(f"Sort {s} is not supported")
9494

0 commit comments

Comments
 (0)