Skip to content

Commit 02a21cd

Browse files
committed
Add builtin warning classes
1 parent d64554d commit 02a21cd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

vm/src/builtins.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,19 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
767767
"ZeroDivisionError" => ctx.exceptions.zero_division_error.clone(),
768768
"KeyError" => ctx.exceptions.key_error.clone(),
769769
"OSError" => ctx.exceptions.os_error.clone(),
770+
771+
// Warnings
772+
"Warning" => ctx.exceptions.warning.clone(),
773+
"BytesWarning" => ctx.exceptions.bytes_warning.clone(),
774+
"UnicodeWarning" => ctx.exceptions.unicode_warning.clone(),
775+
"DeprecationWarning" => ctx.exceptions.deprecation_warning.clone(),
776+
"PendingDeprecationWarning" => ctx.exceptions.pending_deprecation_warning.clone(),
777+
"FutureWarning" => ctx.exceptions.future_warning.clone(),
778+
"ImportWarning" => ctx.exceptions.import_warning.clone(),
779+
"SyntaxWarning" => ctx.exceptions.syntax_warning.clone(),
780+
"ResourceWarning" => ctx.exceptions.resource_warning.clone(),
781+
"RuntimeWarning" => ctx.exceptions.runtime_warning.clone(),
782+
"UserWarning" => ctx.exceptions.user_warning.clone(),
770783
});
771784
}
772785

vm/src/exceptions.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ pub struct ExceptionZoo {
103103
pub type_error: PyClassRef,
104104
pub value_error: PyClassRef,
105105
pub zero_division_error: PyClassRef,
106+
107+
pub warning: PyClassRef,
108+
pub bytes_warning: PyClassRef,
109+
pub unicode_warning: PyClassRef,
110+
pub deprecation_warning: PyClassRef,
111+
pub pending_deprecation_warning: PyClassRef,
112+
pub future_warning: PyClassRef,
113+
pub import_warning: PyClassRef,
114+
pub syntax_warning: PyClassRef,
115+
pub resource_warning: PyClassRef,
116+
pub runtime_warning: PyClassRef,
117+
pub user_warning: PyClassRef,
106118
}
107119

108120
impl ExceptionZoo {
@@ -130,6 +142,19 @@ impl ExceptionZoo {
130142
let file_not_found_error = create_type("FileNotFoundError", &type_type, &os_error);
131143
let permission_error = create_type("PermissionError", &type_type, &os_error);
132144

145+
let warning = create_type("Warning", &type_type, &exception_type);
146+
let bytes_warning = create_type("BytesWarning", &type_type, &warning);
147+
let unicode_warning = create_type("UnicodeWarning", &type_type, &warning);
148+
let deprecation_warning = create_type("DeprecationWarning", &type_type, &warning);
149+
let pending_deprecation_warning =
150+
create_type("PendingDeprecationWarning", &type_type, &warning);
151+
let future_warning = create_type("FutureWarning", &type_type, &warning);
152+
let import_warning = create_type("ImportWarning", &type_type, &warning);
153+
let syntax_warning = create_type("SyntaxWarning", &type_type, &warning);
154+
let resource_warning = create_type("ResourceWarning", &type_type, &warning);
155+
let runtime_warning = create_type("RuntimeWarning", &type_type, &warning);
156+
let user_warning = create_type("UserWarning", &type_type, &warning);
157+
133158
ExceptionZoo {
134159
arithmetic_error,
135160
assertion_error,
@@ -152,6 +177,17 @@ impl ExceptionZoo {
152177
type_error,
153178
value_error,
154179
zero_division_error,
180+
warning,
181+
bytes_warning,
182+
unicode_warning,
183+
deprecation_warning,
184+
pending_deprecation_warning,
185+
future_warning,
186+
import_warning,
187+
syntax_warning,
188+
resource_warning,
189+
runtime_warning,
190+
user_warning,
155191
}
156192
}
157193
}

0 commit comments

Comments
 (0)