Skip to content

Commit e79a6a5

Browse files
committed
Add EncodingWarning from CPython 3.10
1 parent 4c4dec1 commit e79a6a5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Lib/test/exception_hierarchy.txt

+1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ BaseException
6161
+-- ImportWarning
6262
+-- UnicodeWarning
6363
+-- BytesWarning
64+
+-- EncodingWarning
6465
+-- ResourceWarning

vm/src/exceptions.rs

+10
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ pub struct ExceptionZoo {
387387
pub unicode_warning: PyTypeRef,
388388
pub bytes_warning: PyTypeRef,
389389
pub resource_warning: PyTypeRef,
390+
pub encoding_warning: PyTypeRef,
390391
}
391392

392393
macro_rules! extend_exception {
@@ -603,6 +604,7 @@ impl ExceptionZoo {
603604
let unicode_warning = PyUnicodeWarning::init_bare_type().clone();
604605
let bytes_warning = PyBytesWarning::init_bare_type().clone();
605606
let resource_warning = PyResourceWarning::init_bare_type().clone();
607+
let encoding_warning = PyEncodingWarning::init_bare_type().clone();
606608

607609
Self {
608610
base_exception_type,
@@ -673,6 +675,7 @@ impl ExceptionZoo {
673675
unicode_warning,
674676
bytes_warning,
675677
resource_warning,
678+
encoding_warning,
676679
}
677680
}
678681

@@ -837,6 +840,7 @@ impl ExceptionZoo {
837840
extend_exception!(PyUnicodeWarning, ctx, &excs.unicode_warning);
838841
extend_exception!(PyBytesWarning, ctx, &excs.bytes_warning);
839842
extend_exception!(PyResourceWarning, ctx, &excs.resource_warning);
843+
extend_exception!(PyEncodingWarning, ctx, &excs.encoding_warning);
840844
}
841845
}
842846

@@ -1524,4 +1528,10 @@ pub(super) mod types {
15241528
resource_warning,
15251529
"Base class for warnings about resource usage."
15261530
}
1531+
define_exception! {
1532+
PyEncodingWarning,
1533+
PyWarning,
1534+
encoding_warning,
1535+
"Base class for warnings about encodings."
1536+
}
15271537
}

vm/src/stdlib/builtins.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
10301030
"UnicodeWarning" => ctx.exceptions.unicode_warning.clone(),
10311031
"BytesWarning" => ctx.exceptions.bytes_warning.clone(),
10321032
"ResourceWarning" => ctx.exceptions.resource_warning.clone(),
1033+
"EncodingWarning" => ctx.exceptions.encoding_warning.clone(),
10331034
});
10341035

10351036
#[cfg(feature = "jit")]

0 commit comments

Comments
 (0)