Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(167498)

Delta Between Two Patch Sets: Objects/descrobject.c

Issue 11610: Improving property to accept abstract methods
Left Patch Set: Created 8 years ago
Right Patch Set: Created 8 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Misc/ACKS ('k') | Objects/funcobject.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* Descriptors -- a new, flexible way to describe attributes */ 1 /* Descriptors -- a new, flexible way to describe attributes */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "structmember.h" /* Why is this not included in Python.h? */ 4 #include "structmember.h" /* Why is this not included in Python.h? */
5 5
6 static void 6 static void
7 descr_dealloc(PyDescrObject *descr) 7 descr_dealloc(PyDescrObject *descr)
8 { 8 {
9 _PyObject_GC_UNTRACK(descr); 9 _PyObject_GC_UNTRACK(descr);
10 Py_XDECREF(descr->d_type); 10 Py_XDECREF(descr->d_type);
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 PyErr_Clear(); 1322 PyErr_Clear();
1323 } 1323 }
1324 else { 1324 else {
1325 return -1; 1325 return -1;
1326 } 1326 }
1327 } 1327 }
1328 1328
1329 return 0; 1329 return 0;
1330 } 1330 }
1331 1331
1332 static int 1332 static PyObject *
1333 property_check_isabstract(propertyobject *self, PyObject *obj) 1333 property_get___isabstractmethod__(propertyobject *prop, void *closure)
1334 { 1334 {
1335 int res; 1335 int res = _PyObject_IsAbstract(prop->prop_get);
1336 if (obj == NULL) 1336 if (res == -1) {
1337 return 0; 1337 return NULL;
1338 1338 }
1339 _Py_IDENTIFIER(__isabstractmethod__); 1339 else if (res) {
Benjamin Peterson 2011/12/04 22:56:35 Needs to go at beginning of function.
1340 PyObject* isabstract = _PyObject_GetAttrId(obj, &PyId___isabstractmethod__);
Benjamin Peterson 2011/12/04 22:56:35 As does this declaration.
dsdale24 2011/12/05 14:59:17 Ok, but you find declarations like these in the mi
Benjamin Peterson 2011/12/05 15:13:15 They all occur at the beginning of blocks.
1341 if (isabstract == NULL) {
1342 if (PyErr_ExceptionMatches(PyExc_AttributeError))
1343 PyErr_Clear();
1344 return 0;
Benjamin Peterson 2011/12/04 22:56:35 This should be -1.
dsdale24 2011/12/05 15:10:36 Are you sure? property_get__isabstractmethod__ cal
1345 }
1346 res = PyObject_IsTrue(isabstract);
1347 Py_DECREF(isabstract);
1348 return res;
1349 }
1350
1351 static PyObject *
1352 property_get__isabstractmethod__(propertyobject *prop, void *closure)
Benjamin Peterson 2011/12/04 22:56:35 There should probably be 3 underscores before isab
1353 {
1354 int res = property_check_isabstract(prop, prop->prop_get);
1355 if (res == -1)
1356 return NULL;
1357 else if (res)
1358 Py_RETURN_TRUE; 1340 Py_RETURN_TRUE;
1359 1341 }
1360 res = property_check_isabstract(prop, prop->prop_set); 1342
1361 if (res == -1) 1343 res = _PyObject_IsAbstract(prop->prop_set);
1362 return NULL; 1344 if (res == -1) {
1363 else if (res) 1345 return NULL;
1346 }
1347 else if (res) {
1364 Py_RETURN_TRUE; 1348 Py_RETURN_TRUE;
1365 1349 }
1366 res = property_check_isabstract(prop, prop->prop_del); 1350
1367 if (res == -1) 1351 res = _PyObject_IsAbstract(prop->prop_del);
1368 return NULL; 1352 if (res == -1) {
1369 else if (res) 1353 return NULL;
1354 }
1355 else if (res) {
1370 Py_RETURN_TRUE; 1356 Py_RETURN_TRUE;
1371 1357 }
1372 Py_RETURN_FALSE; 1358 Py_RETURN_FALSE;
1373 } 1359 }
1374 1360
1375 static PyGetSetDef property_getsetlist[] = { 1361 static PyGetSetDef property_getsetlist[] = {
1376 {"__isabstractmethod__", 1362 {"__isabstractmethod__",
1377 (getter)property_get__isabstractmethod__, NULL, 1363 (getter)property_get___isabstractmethod__, NULL,
1378 NULL, 1364 NULL,
1379 NULL}, 1365 NULL},
1380 {NULL} /* Sentinel */ 1366 {NULL} /* Sentinel */
1381 }; 1367 };
1382 1368
1383 PyDoc_STRVAR(property_doc, 1369 PyDoc_STRVAR(property_doc,
1384 "property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n" 1370 "property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n"
1385 "\n" 1371 "\n"
1386 "fget is a function to be used for getting an attribute value, and likewise\n" 1372 "fget is a function to be used for getting an attribute value, and likewise\n"
1387 "fset is a function for setting, and fdel a function for del'ing, an\n" 1373 "fset is a function for setting, and fdel a function for del'ing, an\n"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 0, /* tp_base */ 1435 0, /* tp_base */
1450 0, /* tp_dict */ 1436 0, /* tp_dict */
1451 property_descr_get, /* tp_descr_get */ 1437 property_descr_get, /* tp_descr_get */
1452 property_descr_set, /* tp_descr_set */ 1438 property_descr_set, /* tp_descr_set */
1453 0, /* tp_dictoffset */ 1439 0, /* tp_dictoffset */
1454 property_init, /* tp_init */ 1440 property_init, /* tp_init */
1455 PyType_GenericAlloc, /* tp_alloc */ 1441 PyType_GenericAlloc, /* tp_alloc */
1456 PyType_GenericNew, /* tp_new */ 1442 PyType_GenericNew, /* tp_new */
1457 PyObject_GC_Del, /* tp_free */ 1443 PyObject_GC_Del, /* tp_free */
1458 }; 1444 };
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+