Skip to content

Commit f448820

Browse files
committed
clean up type stubs and expose the is_valid function to the user
1 parent 672fb18 commit f448820

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

lib_sudoku.pyi

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if TYPE_CHECKING:
5151
"""
5252
...
5353

54-
def print_puzz(puzzle: list) -> None:
54+
def print_puzz(puzzle: bytearray) -> None:
5555
"""
5656
Prints a puzzle in the correct format.
5757
:param puzzle:
@@ -77,7 +77,7 @@ if TYPE_CHECKING:
7777
"""
7878
...
7979

80-
def solve(puzzle: list) -> bytearray:
80+
def solve(puzzle: bytearray) -> bytearray:
8181
"""
8282
Takes in a puzzle in the form of a row-major list and returns a solved version.
8383
@@ -97,6 +97,18 @@ if TYPE_CHECKING:
9797
num_hints (int): The number of hints the final puzzle will have. Must be between 23 and 40.
9898
9999
returns:
100-
bytearray: The puzzle with the specified number of hints.
100+
bytearray: The puzzle with the specified number of hints.
101101
"""
102102
...
103+
104+
def is_valid(puzzle:bytearray) -> bool:
105+
"""
106+
Checks if a puzzle is legal.
107+
108+
Args:
109+
puzzle (bytearray): The puzzle you want to check.
110+
111+
returns:
112+
bool: True if the puzzle is valid, false otherwise.
113+
"""
114+
...

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "lib_sudoku"
7-
version = "2.0.0"
7+
version = "2.1.0"
88
requires-python = ">=3.8"
99
description = "A blazing fast sudoku library buit in rust"
1010
readme = "README.md"

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn lib_sudoku(m: &Bound<'_, PyModule>) -> PyResult<()> {
1212
m.add_function(wrap_pyfunction!(libraries::speedtest::async_speedtest, m)?)?;
1313
m.add_function(wrap_pyfunction!(libraries::puzzle_solver::solve, m)?)?;
1414
m.add_function(wrap_pyfunction!(libraries::puzzle_generator::gen_unsolved, m)?)?;
15+
m.add_function(wrap_pyfunction!(libraries::puzzle_solver::is_valid, m)?)?;
1516
Ok(())
1617

1718
}

src/libraries/puzzle_solver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn no_repeats(items: Vec<u8>) -> bool {
2323
}
2424

2525
#[pyfunction]
26-
fn is_valid(puzzle: Vec<u8>) -> PyResult<bool> {
26+
pub(crate) fn is_valid(puzzle: Vec<u8>) -> PyResult<bool> {
2727
if puzzle.len() != 81 {
2828
return Err(pyo3::exceptions::PyValueError::new_err("A puzzle must have a length of 81!"));
2929
}

0 commit comments

Comments
 (0)