mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/vm: Don't emit warning when using "raise ... from None".
"Raise SomeException() from None" is a common Python idiom to suppress chained exceptions and thus shouldn't trigger a warning on a version of Python that doesn't support them in the first place.
This commit is contained in:
committed by
Damien George
parent
5232847771
commit
3fb1bb131f
6
py/vm.c
6
py/vm.c
@@ -1171,8 +1171,10 @@ unwind_return:
|
|||||||
|
|
||||||
ENTRY(MP_BC_RAISE_FROM): {
|
ENTRY(MP_BC_RAISE_FROM): {
|
||||||
MARK_EXC_IP_SELECTIVE();
|
MARK_EXC_IP_SELECTIVE();
|
||||||
mp_warning(NULL, "exception chaining not supported");
|
mp_obj_t from_value = POP();
|
||||||
sp--; // ignore (pop) "from" argument
|
if (from_value != mp_const_none) {
|
||||||
|
mp_warning(NULL, "exception chaining not supported");
|
||||||
|
}
|
||||||
mp_obj_t obj = mp_make_raise_obj(TOP());
|
mp_obj_t obj = mp_make_raise_obj(TOP());
|
||||||
RAISE(obj);
|
RAISE(obj);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
# Exception chaining is not supported, but check that basic
|
# Exception chaining is not supported, but check that basic
|
||||||
# exception works as expected.
|
# exception works as expected.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
raise Exception from None
|
raise Exception from None
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Caught Exception")
|
print("Caught Exception")
|
||||||
|
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
raise ValueError("Value")
|
||||||
|
except Exception as exc:
|
||||||
|
raise RuntimeError("Runtime") from exc
|
||||||
|
except Exception as ex2:
|
||||||
|
print("Caught Exception:", ex2)
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
Warning: exception chaining not supported
|
|
||||||
Caught Exception
|
Caught Exception
|
||||||
|
Warning: exception chaining not supported
|
||||||
|
Caught Exception: Runtime
|
||||||
|
|||||||
Reference in New Issue
Block a user