Some style nits. Also clarify in the docstrings what __sizeof__ does.
This commit is contained in:
parent
4f2c998ca9
commit
7a6de8b0f4
|
@ -419,7 +419,7 @@ class SizeofTest(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.file.close()
|
self.file.close()
|
||||||
os.remove(test.test_support.TESTFN)
|
test.test_support.unlink(test.test_support.TESTFN)
|
||||||
|
|
||||||
def check_sizeof(self, o, size):
|
def check_sizeof(self, o, size):
|
||||||
result = sys.getsizeof(o)
|
result = sys.getsizeof(o)
|
||||||
|
@ -435,13 +435,13 @@ class SizeofTest(unittest.TestCase):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def test_align(self):
|
def test_align(self):
|
||||||
self.assertTrue( (self.align(0) % self.p) == 0 )
|
self.assertEqual(self.align(0) % self.p, 0)
|
||||||
self.assertTrue( (self.align(1) % self.p) == 0 )
|
self.assertEqual(self.align(1) % self.p, 0)
|
||||||
self.assertTrue( (self.align(3) % self.p) == 0 )
|
self.assertEqual(self.align(3) % self.p, 0)
|
||||||
self.assertTrue( (self.align(4) % self.p) == 0 )
|
self.assertEqual(self.align(4) % self.p, 0)
|
||||||
self.assertTrue( (self.align(7) % self.p) == 0 )
|
self.assertEqual(self.align(7) % self.p, 0)
|
||||||
self.assertTrue( (self.align(8) % self.p) == 0 )
|
self.assertEqual(self.align(8) % self.p, 0)
|
||||||
self.assertTrue( (self.align(9) % self.p) == 0 )
|
self.assertEqual(self.align(9) % self.p, 0)
|
||||||
|
|
||||||
def test_standardtypes(self):
|
def test_standardtypes(self):
|
||||||
i = self.i
|
i = self.i
|
||||||
|
@ -507,7 +507,7 @@ class SizeofTest(unittest.TestCase):
|
||||||
self.check_sizeof(abs, h + 3*p)
|
self.check_sizeof(abs, h + 3*p)
|
||||||
# module
|
# module
|
||||||
self.check_sizeof(unittest, h + p)
|
self.check_sizeof(unittest, h + p)
|
||||||
# xange
|
# xrange
|
||||||
self.check_sizeof(xrange(1), h + 3*p)
|
self.check_sizeof(xrange(1), h + 3*p)
|
||||||
# slice
|
# slice
|
||||||
self.check_sizeof(slice(0), h + 3*p)
|
self.check_sizeof(slice(0), h + 3*p)
|
||||||
|
@ -520,8 +520,8 @@ class SizeofTest(unittest.TestCase):
|
||||||
# type (PyTypeObject + PyNumberMethods + PyMappingMethods +
|
# type (PyTypeObject + PyNumberMethods + PyMappingMethods +
|
||||||
# PySequenceMethods + PyBufferProcs)
|
# PySequenceMethods + PyBufferProcs)
|
||||||
len_typeobject = p + 2*l + 15*p + l + 4*p + l + 9*p + l + 11*p
|
len_typeobject = p + 2*l + 15*p + l + 4*p + l + 9*p + l + 11*p
|
||||||
self.check_sizeof(class_newstyle, h + \
|
self.check_sizeof(class_newstyle,
|
||||||
len_typeobject + 42*p + 10*p + 3*p + 6*p)
|
h + len_typeobject + 42*p + 10*p + 3*p + 6*p)
|
||||||
|
|
||||||
|
|
||||||
def test_specialtypes(self):
|
def test_specialtypes(self):
|
||||||
|
|
|
@ -3918,7 +3918,7 @@ string_splitlines(PyBytesObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(sizeof__doc__,
|
PyDoc_STRVAR(sizeof__doc__,
|
||||||
"S.__sizeof__() -> size of S in bytes");
|
"S.__sizeof__() -> size of S in memory, in bytes");
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
string_sizeof(PyBytesObject *v)
|
string_sizeof(PyBytesObject *v)
|
||||||
|
|
|
@ -2052,7 +2052,7 @@ PyDoc_STRVAR(contains__doc__,
|
||||||
PyDoc_STRVAR(getitem__doc__, "x.__getitem__(y) <==> x[y]");
|
PyDoc_STRVAR(getitem__doc__, "x.__getitem__(y) <==> x[y]");
|
||||||
|
|
||||||
PyDoc_STRVAR(sizeof__doc__,
|
PyDoc_STRVAR(sizeof__doc__,
|
||||||
"D.__sizeof__() -> size of D in bytes");
|
"D.__sizeof__() -> size of D in memory, in bytes");
|
||||||
|
|
||||||
PyDoc_STRVAR(get__doc__,
|
PyDoc_STRVAR(get__doc__,
|
||||||
"D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.");
|
"D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.");
|
||||||
|
|
|
@ -2437,7 +2437,7 @@ PyDoc_STRVAR(getitem_doc,
|
||||||
PyDoc_STRVAR(reversed_doc,
|
PyDoc_STRVAR(reversed_doc,
|
||||||
"L.__reversed__() -- return a reverse iterator over the list");
|
"L.__reversed__() -- return a reverse iterator over the list");
|
||||||
PyDoc_STRVAR(sizeof_doc,
|
PyDoc_STRVAR(sizeof_doc,
|
||||||
"L.__sizeof__() -- size of L in bytes");
|
"L.__sizeof__() -- size of L in memory, in bytes");
|
||||||
PyDoc_STRVAR(append_doc,
|
PyDoc_STRVAR(append_doc,
|
||||||
"L.append(object) -- append object to end");
|
"L.append(object) -- append object to end");
|
||||||
PyDoc_STRVAR(extend_doc,
|
PyDoc_STRVAR(extend_doc,
|
||||||
|
|
|
@ -3467,7 +3467,7 @@ static PyMethodDef long_methods[] = {
|
||||||
{"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS},
|
{"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS},
|
||||||
{"__format__", (PyCFunction)long__format__, METH_VARARGS},
|
{"__format__", (PyCFunction)long__format__, METH_VARARGS},
|
||||||
{"__sizeof__", (PyCFunction)long_sizeof, METH_NOARGS,
|
{"__sizeof__", (PyCFunction)long_sizeof, METH_NOARGS,
|
||||||
"Returns size in bytes"},
|
"Returns size in memory, in bytes"},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3421,7 +3421,7 @@ static PyMethodDef object_methods[] = {
|
||||||
{"__format__", object_format, METH_VARARGS,
|
{"__format__", object_format, METH_VARARGS,
|
||||||
PyDoc_STR("default object formatter")},
|
PyDoc_STR("default object formatter")},
|
||||||
{"__sizeof__", object_sizeof, METH_NOARGS,
|
{"__sizeof__", object_sizeof, METH_NOARGS,
|
||||||
PyDoc_STR("__sizeof__() -> size of object in bytes")},
|
PyDoc_STR("__sizeof__() -> size of object in memory, in bytes")},
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -664,9 +664,9 @@ sys_getsizeof(PyObject *self, PyObject *args)
|
||||||
return PyObject_CallFunctionObjArgs(method, args, NULL);
|
return PyObject_CallFunctionObjArgs(method, args, NULL);
|
||||||
}
|
}
|
||||||
/* Instance of old-style classes */
|
/* Instance of old-style classes */
|
||||||
else if(PyInstance_Check(args))
|
else if (PyInstance_Check(args))
|
||||||
return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize);
|
return PyInt_FromSsize_t(PyInstance_Type.tp_basicsize);
|
||||||
/* Old-style class */
|
/* Old-style classes */
|
||||||
else if (PyClass_Check(args))
|
else if (PyClass_Check(args))
|
||||||
return PyInt_FromSsize_t(PyClass_Type.tp_basicsize);
|
return PyInt_FromSsize_t(PyClass_Type.tp_basicsize);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue