Skip to content

Commit fa46ab1

Browse files
authored
Merge pull request RustPython#2115 from minoring/support-__all__
Support __all__
2 parents 861aa4d + 7545635 commit fa46ab1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Lib/_codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
'latin_1_encode', 'mbcs_decode', 'readbuffer_encode', 'escape_encode',
4747
'utf_8_decode', 'raw_unicode_escape_decode', 'utf_7_decode',
4848
'unicode_escape_encode', 'latin_1_decode', 'utf_16_decode',
49-
'unicode_escape_decode', 'ascii_decode', 'charmap_encode',
49+
'unicode_escape_decode', 'ascii_decode', 'charmap_encode', 'charmap_build',
5050
'unicode_internal_encode', 'unicode_internal_decode', 'utf_16_ex_decode',
5151
'escape_decode', 'charmap_decode', 'utf_7_encode', 'mbcs_encode',
5252
'ascii_encode', 'utf_16_encode', 'raw_unicode_escape_encode', 'utf_8_encode',

Lib/asyncio/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED',
55
'wait', 'wait_for', 'as_completed', 'sleep', 'async',
66
'gather', 'shield', 'ensure_future', 'run_coroutine_threadsafe',
7+
'all_tasks'
78
]
89

910
import concurrent.futures

vm/src/frame.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::obj::objgenerator::PyGenerator;
1919
use crate::obj::objiter;
2020
use crate::obj::objlist;
2121
use crate::obj::objslice::PySlice;
22-
use crate::obj::objstr::{self, PyString};
22+
use crate::obj::objstr::{self, PyString, PyStringRef};
2323
use crate::obj::objtraceback::PyTraceback;
2424
use crate::obj::objtuple::PyTuple;
2525
use crate::obj::objtype::{self, PyClassRef};
@@ -797,10 +797,21 @@ impl ExecutingFrame<'_> {
797797

798798
// Grab all the names from the module and put them in the context
799799
if let Some(dict) = module.dict() {
800+
let filter_pred: Box<dyn Fn(&str) -> bool> =
801+
if let Ok(all) = dict.get_item("__all__", vm) {
802+
let all: Vec<PyStringRef> = vm.extract_elements(&all)?;
803+
let all: Vec<String> = all
804+
.into_iter()
805+
.map(|name| name.as_ref().to_owned())
806+
.collect();
807+
Box::new(move |name| all.contains(&name.to_owned()))
808+
} else {
809+
Box::new(|name| !name.starts_with('_'))
810+
};
800811
for (k, v) in &dict {
801-
let k = vm.to_str(&k)?;
802-
let k = k.borrow_value();
803-
if !k.starts_with('_') {
812+
let k = PyStringRef::try_from_object(vm, k)?;
813+
let k = k.as_ref();
814+
if filter_pred(k) {
804815
self.scope.store_name(&vm, k, v);
805816
}
806817
}

0 commit comments

Comments
 (0)