Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c6bc2c

Browse filesBrowse files
authored
Add _suggestions module (#5675)
1 parent be56911 commit 3c6bc2c
Copy full SHA for 3c6bc2c

File tree

3 files changed

+23
-1
lines changed
Filter options

3 files changed

+23
-1
lines changed

‎stdlib/src/lib.rs

Copy file name to clipboardExpand all lines: stdlib/src/lib.rs
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod pyexpat;
3333
mod pystruct;
3434
mod random;
3535
mod statistics;
36+
mod suggestions;
3637
// TODO: maybe make this an extension module, if we ever get those
3738
// mod re;
3839
#[cfg(feature = "bz2")]
@@ -133,6 +134,7 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
133134
"unicodedata" => unicodedata::make_module,
134135
"zlib" => zlib::make_module,
135136
"_statistics" => statistics::make_module,
137+
"suggestions" => suggestions::make_module,
136138
// crate::vm::sysmodule::sysconfigdata_name() => sysconfigdata::make_module,
137139
}
138140
#[cfg(any(unix, target_os = "wasi"))]

‎stdlib/src/suggestions.rs

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub(crate) use _suggestions::make_module;
2+
3+
#[pymodule]
4+
mod _suggestions {
5+
use rustpython_vm::VirtualMachine;
6+
7+
use crate::vm::PyObjectRef;
8+
9+
#[pyfunction]
10+
fn _generate_suggestions(
11+
candidates: Vec<PyObjectRef>,
12+
name: PyObjectRef,
13+
vm: &VirtualMachine,
14+
) -> PyObjectRef {
15+
match crate::vm::suggestion::calculate_suggestions(candidates.iter(), &name) {
16+
Some(suggestion) => suggestion.into(),
17+
None => vm.ctx.none(),
18+
}
19+
}
20+
}

‎vm/src/suggestion.rs

Copy file name to clipboardExpand all lines: vm/src/suggestion.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::iter::ExactSizeIterator;
1212

1313
const MAX_CANDIDATE_ITEMS: usize = 750;
1414

15-
fn calculate_suggestions<'a>(
15+
pub fn calculate_suggestions<'a>(
1616
dir_iter: impl ExactSizeIterator<Item = &'a PyObjectRef>,
1717
name: &PyObjectRef,
1818
) -> Option<PyStrRef> {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.