Commit 4a5c9554 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Translate errors in thread.local.__getattr__ to AttributeErrors

parent 8cefa4d3
......@@ -175,7 +175,12 @@ public:
Box* tls_obj = getThreadLocalObject(obj);
if (!strcmp(name, "__dict__"))
return tls_obj;
return getitem(tls_obj, boxString(name));
try {
return getitem(tls_obj, boxString(name));
} catch (ExcInfo e) {
raiseExcHelper(AttributeError, "'%.50s' object has no attribute '%.400s'", obj->cls->tp_name, name);
}
}
static Box* hash(Box* obj) { return boxInt(PyThread_get_thread_ident()); }
......
......@@ -232,9 +232,11 @@ extern "C" PyObject* PyDict_GetItem(PyObject* dict, PyObject* key) noexcept {
try {
return getitem(dict, key);
} catch (ExcInfo e) {
if (e.matches(KeyError))
return NULL;
abort();
// PyDict_GetItem has special error behavior in CPython for backwards-compatibility reasons,
// and apparently it's important enough that we have to follow that.
// The behavior is that all errors get suppressed, and in fact I think it's supposed to
// restore the previous exception afterwards (we don't do that yet).
return NULL;
}
}
......
......@@ -12,3 +12,4 @@ thread.start()
thread.join()
print a.x
print getattr(a, "doesnt_exist", 5)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment