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

Side by Side Diff: Objects/descrobject.c

Issue 11610: Improving property to accept abstract methods
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:
View unified diff | Download patch
OLDNEW
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 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 else if (PyErr_ExceptionMatches(PyExc_Exception)) { 1321 else if (PyErr_ExceptionMatches(PyExc_Exception)) {
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
1332 static int
1333 property_check_isabstract(propertyobject *self, PyObject *obj)
1334 {
1335 int res;
1336 if (obj == NULL)
1337 return 0;
1338
1339 _Py_IDENTIFIER(__isabstractmethod__);
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;
1359
1360 res = property_check_isabstract(prop, prop->prop_set);
1361 if (res == -1)
1362 return NULL;
1363 else if (res)
1364 Py_RETURN_TRUE;
1365
1366 res = property_check_isabstract(prop, prop->prop_del);
1367 if (res == -1)
1368 return NULL;
1369 else if (res)
1370 Py_RETURN_TRUE;
1371
1372 Py_RETURN_FALSE;
1373 }
1374
1375 static PyGetSetDef property_getsetlist[] = {
1376 {"__isabstractmethod__",
1377 (getter)property_get__isabstractmethod__, NULL,
1378 NULL,
1379 NULL},
1380 {NULL} /* Sentinel */
1381 };
1331 1382
1332 PyDoc_STRVAR(property_doc, 1383 PyDoc_STRVAR(property_doc,
1333 "property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n" 1384 "property(fget=None, fset=None, fdel=None, doc=None) -> property attribute\n"
1334 "\n" 1385 "\n"
1335 "fget is a function to be used for getting an attribute value, and likewise\n" 1386 "fget is a function to be used for getting an attribute value, and likewise\n"
1336 "fset is a function for setting, and fdel a function for del'ing, an\n" 1387 "fset is a function for setting, and fdel a function for del'ing, an\n"
1337 "attribute. Typical use is to define a managed attribute x:\n" 1388 "attribute. Typical use is to define a managed attribute x:\n"
1338 "class C(object):\n" 1389 "class C(object):\n"
1339 " def getx(self): return self._x\n" 1390 " def getx(self): return self._x\n"
1340 " def setx(self, value): self._x = value\n" 1391 " def setx(self, value): self._x = value\n"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 Py_TPFLAGS_BASETYPE, /* tp_flags */ 1438 Py_TPFLAGS_BASETYPE, /* tp_flags */
1388 property_doc, /* tp_doc */ 1439 property_doc, /* tp_doc */
1389 property_traverse, /* tp_traverse */ 1440 property_traverse, /* tp_traverse */
1390 0, /* tp_clear */ 1441 0, /* tp_clear */
1391 0, /* tp_richcompare */ 1442 0, /* tp_richcompare */
1392 0, /* tp_weaklistoffset */ 1443 0, /* tp_weaklistoffset */
1393 0, /* tp_iter */ 1444 0, /* tp_iter */
1394 0, /* tp_iternext */ 1445 0, /* tp_iternext */
1395 property_methods, /* tp_methods */ 1446 property_methods, /* tp_methods */
1396 property_members, /* tp_members */ 1447 property_members, /* tp_members */
1397 0, /* tp_getset */ 1448 property_getsetlist, /* tp_getset */
1398 0, /* tp_base */ 1449 0, /* tp_base */
1399 0, /* tp_dict */ 1450 0, /* tp_dict */
1400 property_descr_get, /* tp_descr_get */ 1451 property_descr_get, /* tp_descr_get */
1401 property_descr_set, /* tp_descr_set */ 1452 property_descr_set, /* tp_descr_set */
1402 0, /* tp_dictoffset */ 1453 0, /* tp_dictoffset */
1403 property_init, /* tp_init */ 1454 property_init, /* tp_init */
1404 PyType_GenericAlloc, /* tp_alloc */ 1455 PyType_GenericAlloc, /* tp_alloc */
1405 PyType_GenericNew, /* tp_new */ 1456 PyType_GenericNew, /* tp_new */
1406 PyObject_GC_Del, /* tp_free */ 1457 PyObject_GC_Del, /* tp_free */
1407 }; 1458 };
OLDNEW
« no previous file with comments | « Misc/ACKS ('k') | Objects/funcobject.c » ('j') | Objects/funcobject.c » ('J')

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