Skip to content

Commit 26bc7f9

Browse files
Add stubtests
1 parent dad5ba4 commit 26bc7f9

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
; https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
22
[flake8]
33
max-line-length = 88
4-
extend-ignore = E203,E501,F405,F403
4+
extend-ignore = E203,E501,F405,F403,E302

.github/workflows/CI.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ jobs:
3030
- uses: actions/checkout@v2
3131
- run: pip install -e .[test]
3232
- run: pytest
33+
stubtest:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/setup-python@v2
37+
with:
38+
python-version: "3.10"
39+
- uses: actions/checkout@v2
40+
- run: pip install -e . mypy
41+
- run: python -m mypy.stubtest egg_smol.bindings
3342
docs:
3443
runs-on: ubuntu-latest
3544
steps:

docs/how-to-guides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ To get started developing on this package:
2424
3. Run the tests: `pytest`
2525
4. Run the pre-commit hooks: `pre-commit run --all-files`
2626
5. Build the docs: `sphinx-build -nW -b html docs docs/_build/html`
27+
6. Check the stubts: `python -m mypy.stubtest egg_smol.bindings`

python/egg_smol/bindings.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ from .bindings_py import Expr, FunctionDecl, Variant
66

77
@final
88
class EGraph:
9-
def ___init__(self) -> None: ...
10-
def parse_and_run_program(self, program: str) -> list[str]: ...
9+
def parse_and_run_program(self, input: str) -> list[str]: ...
1110
def declare_constructor(self, variant: Variant, sort: str) -> None: ...
1211
def declare_sort(self, name: str) -> None: ...
13-
def declare_function(self, function: FunctionDecl) -> None: ...
12+
def declare_function(self, decl: FunctionDecl) -> None: ...
1413
def define(self, name: str, expr: Expr, cost: Optional[int] = None) -> None: ...
1514

1615
@final
1716
class EggSmolError(Exception):
18-
pass
17+
context: str

src/lib.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,41 @@ impl EGraph {
2222
}
2323
}
2424

25-
/// define($self, expr, name, cost)
26-
/// --
27-
///
2825
/// Define a new named value.
29-
#[args(cost = "None")]
26+
#[pyo3(
27+
text_signature = "($self, name, expr, cost=None)",
28+
signature = "(name, expr, cost=None)"
29+
)]
3030
fn define(&mut self, name: String, expr: WrappedExpr, cost: Option<usize>) -> EggResult<()> {
3131
self.egraph.define(name.into(), expr.into(), cost)?;
3232
Ok(())
3333
}
3434

35-
/// declare_function($self, decl)
36-
/// --
37-
///
3835
/// Declare a new function definition.
36+
#[pyo3(text_signature = "($self, decl)")]
3937
fn declare_function(&mut self, decl: WrappedFunctionDecl) -> EggResult<()> {
4038
self.egraph.declare_function(&decl.into())?;
4139
Ok(())
4240
}
4341

44-
/// declare_sort($self, name)
45-
/// --
46-
///
4742
/// Declare a new sort with the given name.
43+
#[pyo3(text_signature = "($self, name)")]
4844
fn declare_sort(&mut self, name: &str) -> EggResult<()> {
4945
self.egraph.declare_sort(name)?;
5046
Ok({})
5147
}
5248

53-
/// declare_constructor($self, variant, sort)
54-
/// --
55-
///
5649
/// Declare a new datatype constructor.
50+
#[pyo3(text_signature = "($self, variant, sort)")]
5751
fn declare_constructor(&mut self, variant: WrappedVariant, sort: &str) -> EggResult<()> {
5852
self.egraph.declare_constructor(variant.into(), sort)?;
5953
Ok({})
6054
}
6155

62-
/// parse_and_run_program($self, input)
63-
/// --
64-
///
6556
/// Parse the input string as a program and run it on the EGraph.
6657
/// Returns a list of strings representing the output.
6758
/// An EggSmolError is raised if there is problem parsing or executing.
59+
#[pyo3(text_signature = "($self, input)")]
6860
fn parse_and_run_program(&mut self, input: &str) -> EggResult<Vec<String>> {
6961
let res = self.egraph.parse_and_run_program(input)?;
7062
Ok(res)

0 commit comments

Comments
 (0)