mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-28 02:10:17 +00:00
Compare commits
1 Commits
a51d7bba02
...
9b854e0373
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b854e0373 |
@ -1143,33 +1143,20 @@ __NEXT_STEP:
|
|||||||
}
|
}
|
||||||
case OP_EXCEPTION_MATCH: {
|
case OP_EXCEPTION_MATCH: {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
bool has_invalid = false;
|
|
||||||
if(TOP()->type == tp_type) {
|
if(TOP()->type == tp_type) {
|
||||||
ok = py_isinstance(&self->unhandled_exc, py_totype(TOP()));
|
ok = py_isinstance(&self->unhandled_exc, py_totype(TOP()));
|
||||||
} else if(TOP()->type == tp_tuple) {
|
} else if(TOP()->type == tp_tuple) {
|
||||||
int len = py_tuple_len(TOP());
|
int len = py_tuple_len(TOP());
|
||||||
py_ObjectRef data = py_tuple_data(TOP());
|
py_ObjectRef data = py_tuple_data(TOP());
|
||||||
for(int i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
if((data + i)->type != tp_type) {
|
if(!py_checktype(data + i, tp_type)) goto __ERROR;
|
||||||
has_invalid = true;
|
if(py_isinstance(&self->unhandled_exc, py_totype(data + i))) {
|
||||||
|
ok = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!has_invalid) {
|
} else
|
||||||
for(int i = 0; i < len; i++) {
|
goto __ERROR;
|
||||||
if(py_isinstance(&self->unhandled_exc, py_totype(data + i))) {
|
|
||||||
ok = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
has_invalid = true;
|
|
||||||
}
|
|
||||||
if(has_invalid) {
|
|
||||||
py_clearexc(NULL);
|
|
||||||
TypeError("catching classes that do not inherit from BaseException is not allowed");
|
|
||||||
}
|
|
||||||
py_newbool(TOP(), ok);
|
py_newbool(TOP(), ok);
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -201,19 +201,6 @@ for i in range(6):
|
|||||||
a.append(i)
|
a.append(i)
|
||||||
assert a == [0, 1, 3, 4, 5]
|
assert a == [0, 1, 3, 4, 5]
|
||||||
|
|
||||||
try:
|
|
||||||
result = 10 / 0
|
|
||||||
except (ZeroDivisionError, TypeError) as e:
|
|
||||||
assert type(e) == ZeroDivisionError
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
result = 10 / 0
|
|
||||||
except (ZeroDivisionError, 1) as e:
|
|
||||||
assert type(e) == ZeroDivisionError
|
|
||||||
except Exception as e:
|
|
||||||
assert type(e) == TypeError
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# finally, only
|
# finally, only
|
||||||
def finally_only():
|
def finally_only():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user