Skip to content

Commit 0fb8cd1

Browse files
committed
feat: add type annotations
Add type annotations and clarify some docstrings.
1 parent 4a5fe1c commit 0fb8cd1

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ mod unicode_segmentation_rs {
2323
.collect())
2424
}
2525

26-
/// Split a string into words
26+
/// Split a string at word boundaries (includes punctuation and whitespace).
2727
#[pyfunction]
2828
fn split_word_bounds(text: &str) -> PyResult<Vec<String>> {
2929
Ok(text.split_word_bounds().map(|s| s.to_string()).collect())
3030
}
3131

32-
/// Split a string into word indices
32+
/// Split a string at word boundaries with byte indices.
3333
#[pyfunction]
3434
fn split_word_bound_indices(text: &str) -> PyResult<Vec<(usize, String)>> {
3535
Ok(text
@@ -38,13 +38,13 @@ mod unicode_segmentation_rs {
3838
.collect())
3939
}
4040

41-
/// Get Unicode words (excluding punctuation and whitespace)
41+
/// Get Unicode words from a string (excludes punctuation and whitespace).
4242
#[pyfunction]
4343
fn unicode_words(text: &str) -> PyResult<Vec<String>> {
4444
Ok(text.unicode_words().map(|s| s.to_string()).collect())
4545
}
4646

47-
/// Split a string into sentences
47+
/// Split a string at word boundaries (includes punctuation and whitespace).
4848
#[pyfunction]
4949
fn unicode_sentences(text: &str) -> PyResult<Vec<String>> {
5050
Ok(text.unicode_sentences().map(|s| s.to_string()).collect())

unicode_segmentation_rs.pyi

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright © Michal Čihař <michal@weblate.org>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Type stubs for unicode-segmentation-rs
6+
7+
This module provides Unicode text segmentation and width calculation.
8+
"""
9+
10+
def graphemes(text: str, is_extended: bool) -> list[str]:
11+
...
12+
13+
def grapheme_indices(text: str, is_extended: bool) -> list[tuple[int, str]]:
14+
...
15+
16+
def split_word_bounds(text: str) -> list[str]:
17+
...
18+
19+
def split_word_bound_indices(text: str) -> list[tuple[int, str]]:
20+
...
21+
22+
def unicode_words(text: str) -> list[str]:
23+
...
24+
25+
def unicode_sentences(text: str) -> list[str]:
26+
...
27+
28+
def text_width(text: str) -> int:
29+
...

0 commit comments

Comments
 (0)