Skip to content

Commit 812cbe6

Browse files
committed
Provide Python 3.15 traceback metadata for missing modules and attributes
Preserve AttributeError context for missing class attribute deletion, matching type_update_dict. Expose canonical generated missing-stdlib messages through the native sysconfig modules without importing CPython build-specific disabled-module assumptions. Assisted-by: OpenAI Codex:model version unavailable
1 parent fe529bc commit 812cbe6

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎crates/vm/src/builtins/type.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,11 +3214,17 @@ impl SetAttr for PyType {
32143214
} else {
32153215
let prev_value = zelf.attributes().remove(attr_name);
32163216
if prev_value.is_none() {
3217-
return Err(vm.new_attribute_error(format!(
3217+
let exc = vm.new_attribute_error(format!(
32183218
"type object '{}' has no attribute '{}'",
32193219
zelf.name(),
32203220
attr_name,
3221-
)));
3221+
));
3222+
vm.set_attribute_error_context(
3223+
&exc,
3224+
zelf.to_owned().into(),
3225+
attr_name.to_owned(),
3226+
);
3227+
return Err(exc);
32223228
}
32233229
prev_value
32243230
};

‎crates/vm/src/stdlib/_sysconfig.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
pub(crate) use _sysconfig::module_def;
22

3+
#[pymodule]
4+
pub(crate) mod _missing_stdlib_info {
5+
use crate::{VirtualMachine, builtins::PyDictRef, convert::ToPyObject};
6+
7+
#[pyattr(name = "_MISSING_STDLIB_MODULE_MESSAGES")]
8+
fn missing_stdlib_module_messages(vm: &VirtualMachine) -> PyDictRef {
9+
let messages = vm.ctx.new_dict();
10+
// CPython's Tools/build/check_extension_modules.py emits these entries
11+
// unconditionally, including on Windows. Do not infer disabled build
12+
// features from CPython's module inventory: ours is different.
13+
for name in [
14+
"_overlapped",
15+
"_testconsole",
16+
"_winapi",
17+
"_wmi",
18+
"msvcrt",
19+
"nt",
20+
"winreg",
21+
"winsound",
22+
] {
23+
let message =
24+
format!("Unsupported platform for Windows-only standard library module '{name}'");
25+
messages
26+
.set_item(name, message.to_pyobject(vm), vm)
27+
.unwrap();
28+
}
29+
// This module is only implemented for macOS in our stdlib as well.
30+
#[cfg(not(target_os = "macos"))]
31+
messages
32+
.set_item(
33+
"_scproxy",
34+
"Unsupported platform for standard library module '_scproxy'".to_pyobject(vm),
35+
vm,
36+
)
37+
.unwrap();
38+
messages
39+
}
40+
}
41+
342
#[pymodule]
443
pub(crate) mod _sysconfig {
544
use crate::{VirtualMachine, builtins::PyDictRef, convert::ToPyObject};

‎crates/vm/src/stdlib/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub fn builtin_module_defs(ctx: &Context) -> Vec<&'static PyModuleDef> {
140140
_symtable::module_def(ctx),
141141
_sysconfigdata::module_def(ctx),
142142
_sysconfig::module_def(ctx),
143+
_sysconfig::_missing_stdlib_info::module_def(ctx),
143144
#[cfg(feature = "threading")]
144145
_thread::module_def(ctx),
145146
_interpchannels::module_def(ctx),

0 commit comments

Comments
 (0)