Skip to content
Prev Previous commit
Next Next commit
Don't add __set__
  • Loading branch information
JelleZijlstra committed Jun 21, 2024
commit 832f6f324704205552c2aefb3c3cbd9ff6973869
5 changes: 0 additions & 5 deletions Lib/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
class TypeAnnotationTests(unittest.TestCase):

def test_lazy_create_annotations(self):
# type objects lazy create their __annotations__ dict on demand.
# the annotations dict is stored in type.__dict__.
# a freshly created type shouldn't have an annotations dict yet.
foo = type("Foo", (), {})
for i in range(3):
self.assertFalse("__annotations__" in foo.__dict__)
d = foo.__annotations__
self.assertTrue("__annotations__" in foo.__dict__)
self.assertEqual(foo.__annotations__, d)
Expand All @@ -27,7 +23,6 @@ def test_lazy_create_annotations(self):
def test_setting_annotations(self):
foo = type("Foo", (), {})
for i in range(3):
self.assertFalse("__annotations__" in foo.__dict__)
d = {'a': int}
foo.__annotations__ = d
self.assertTrue("__annotations__" in foo.__dict__)
Expand Down
13 changes: 0 additions & 13 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11899,18 +11899,6 @@ annodescr_descr_get(PyObject *self, PyObject *obj, PyObject *type)
return Py_NewRef(ad->annotations);
}

static int
annodescr_descr_set(PyObject *self, PyObject *obj, PyObject *value)
{
annodescrobject *ad = (annodescrobject *)self;
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "cannot delete __annotations__");
return -1;
}
Py_XSETREF(ad->annotations, value);
return 0;
}

PyTypeObject _PyAnnotationsDescriptor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "AnnotationsDescriptor",
Expand All @@ -11933,5 +11921,4 @@ PyTypeObject _PyAnnotationsDescriptor_Type = {
.tp_richcompare = annodescr_richcompare,
.tp_methods = annodescr_methods,
.tp_descr_get = annodescr_descr_get,
.tp_descr_set = annodescr_descr_set,
};