Refine the exception type when assigning improper attributes.
diff --git a/python/extension_dict.c b/python/extension_dict.c
index 0111fa6..d466ba9 100644
--- a/python/extension_dict.c
+++ b/python/extension_dict.c
@@ -121,7 +121,7 @@
   const upb_fielddef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
   if (!f) return -1;
   if (val) {
-    return PyUpb_CMessage_SetFieldValue(self->msg, f, val);
+    return PyUpb_CMessage_SetFieldValue(self->msg, f, val, PyExc_TypeError);
   } else {
     PyUpb_CMessage_DoClearField(self->msg, f);
     return 0;
diff --git a/python/message.c b/python/message.c
index 95d873e..19cc862 100644
--- a/python/message.c
+++ b/python/message.c
@@ -823,12 +823,12 @@
 }
 
 int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_fielddef* field,
-                                 PyObject* value) {
+                                 PyObject* value, PyObject* exc) {
   PyUpb_CMessage* self = (void*)_self;
   assert(value);
 
   if (upb_fielddef_issubmsg(field) || upb_fielddef_isseq(field)) {
-    PyErr_Format(PyExc_AttributeError,
+    PyErr_Format(exc,
                  "Assignment not allowed to message, map, or repeated "
                  "field \"%s\" in protocol message object.",
                  upb_fielddef_name(field));
@@ -904,7 +904,7 @@
     return -1;
   }
 
-  return PyUpb_CMessage_SetFieldValue(_self, field, value);
+  return PyUpb_CMessage_SetFieldValue(_self, field, value, PyExc_AttributeError);
 }
 
 static PyObject* PyUpb_CMessage_HasField(PyObject* _self, PyObject* arg) {
diff --git a/python/message.h b/python/message.h
index f67bf63..1f88b8d 100644
--- a/python/message.h
+++ b/python/message.h
@@ -89,7 +89,7 @@
 // Implements the equivalent of setattr(msg, field, value), once `field` has
 // already been resolved to a `upb_fielddef*`.
 int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_fielddef* field,
-                                 PyObject* value);
+                                 PyObject* value, PyObject* exc);
 
 // Returns the version associated with this message.  The version will be
 // incremented when the message changes.
diff --git a/python/pb_unit_tests/reflection_test_wrapper.py b/python/pb_unit_tests/reflection_test_wrapper.py
index 3eaf34d..b72730a 100644
--- a/python/pb_unit_tests/reflection_test_wrapper.py
+++ b/python/pb_unit_tests/reflection_test_wrapper.py
@@ -30,9 +30,6 @@
 # reasonable to guarantee.
 reflection_test.Proto2ReflectionTest.testExtensionIter.__unittest_expecting_failure__ = True
 
-reflection_test.Proto2ReflectionTest.testTopLevelExtensionsForOptionalMessage.__unittest_expecting_failure__ = True
-reflection_test.Proto2ReflectionTest.testTopLevelExtensionsForRepeatedMessage.__unittest_expecting_failure__ = True
-reflection_test.Proto2ReflectionTest.testTopLevelExtensionsForRepeatedScalar.__unittest_expecting_failure__ = True
 reflection_test.ReflectionTest.testDeepCopy_proto2.__unittest_expecting_failure__ = True
 reflection_test.ReflectionTest.testDeepCopy_proto3.__unittest_expecting_failure__ = True
 reflection_test.SerializationTest.testCanonicalSerializationOrder.__unittest_expecting_failure__ = True