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: ...@@ -175,7 +175,12 @@ public:
Box* tls_obj = getThreadLocalObject(obj); Box* tls_obj = getThreadLocalObject(obj);
if (!strcmp(name, "__dict__")) if (!strcmp(name, "__dict__"))
return tls_obj; 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()); } 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 { ...@@ -232,9 +232,11 @@ extern "C" PyObject* PyDict_GetItem(PyObject* dict, PyObject* key) noexcept {
try { try {
return getitem(dict, key); return getitem(dict, key);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (e.matches(KeyError)) // PyDict_GetItem has special error behavior in CPython for backwards-compatibility reasons,
return NULL; // and apparently it's important enough that we have to follow that.
abort(); // 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() ...@@ -12,3 +12,4 @@ thread.start()
thread.join() thread.join()
print a.x 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