mirror of
https://github.com/python/cpython.git
synced 2025-11-08 21:52:45 +00:00
bpo-43901: Fix refleaks in test_module (GH-25754)
This commit is contained in:
parent
7dcf0f6db3
commit
e374a40afa
2 changed files with 13 additions and 5 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import weakref
|
import weakref
|
||||||
from test.support import gc_collect
|
from test.support import gc_collect
|
||||||
|
from test.support import import_helper
|
||||||
from test.support.script_helper import assert_python_ok
|
from test.support.script_helper import assert_python_ok
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -334,7 +335,7 @@ a = A(destroyed)"""
|
||||||
del foo.__annotations__
|
del foo.__annotations__
|
||||||
|
|
||||||
def test_annotations_are_created_correctly(self):
|
def test_annotations_are_created_correctly(self):
|
||||||
from test import ann_module4
|
ann_module4 = import_helper.import_fresh_module('test.ann_module4')
|
||||||
self.assertTrue("__annotations__" in ann_module4.__dict__)
|
self.assertTrue("__annotations__" in ann_module4.__dict__)
|
||||||
del ann_module4.__annotations__
|
del ann_module4.__annotations__
|
||||||
self.assertFalse("__annotations__" in ann_module4.__dict__)
|
self.assertFalse("__annotations__" in ann_module4.__dict__)
|
||||||
|
|
|
||||||
|
|
@ -845,6 +845,7 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
|
||||||
|
|
||||||
if ((dict == NULL) || !PyDict_Check(dict)) {
|
if ((dict == NULL) || !PyDict_Check(dict)) {
|
||||||
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
|
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
|
||||||
|
Py_XDECREF(dict);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -876,25 +877,31 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
|
||||||
static int
|
static int
|
||||||
module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored))
|
module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored))
|
||||||
{
|
{
|
||||||
|
int ret = -1;
|
||||||
PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__);
|
PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__);
|
||||||
|
|
||||||
if ((dict == NULL) || !PyDict_Check(dict)) {
|
if ((dict == NULL) || !PyDict_Check(dict)) {
|
||||||
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
|
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
|
||||||
return -1;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
/* set */
|
/* set */
|
||||||
return _PyDict_SetItemId(dict, &PyId___annotations__, value);
|
ret = _PyDict_SetItemId(dict, &PyId___annotations__, value);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delete */
|
/* delete */
|
||||||
if (!_PyDict_ContainsId(dict, &PyId___annotations__)) {
|
if (!_PyDict_ContainsId(dict, &PyId___annotations__)) {
|
||||||
PyErr_Format(PyExc_AttributeError, "__annotations__");
|
PyErr_Format(PyExc_AttributeError, "__annotations__");
|
||||||
return -1;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _PyDict_DelItemId(dict, &PyId___annotations__);
|
ret = _PyDict_DelItemId(dict, &PyId___annotations__);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
Py_XDECREF(dict);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue