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

Side by Side Diff: Objects/descrobject.c

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 5 months 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 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 else if (PyErr_ExceptionMatches(PyExc_Exception)) { 1318 else if (PyErr_ExceptionMatches(PyExc_Exception)) {
1319 PyErr_Clear(); 1319 PyErr_Clear();
1320 } 1320 }
1321 else { 1321 else {
1322 return -1; 1322 return -1;
1323 } 1323 }
1324 } 1324 }
1325 1325
1326 return 0; 1326 return 0;
1327 } 1327 }
1328
1329 static PyObject *
1330 property_check_isabstract(propertyobject *self, PyObject *obj)
1331 {
1332 if (obj == NULL)
1333 return 0;
1334
1335 PyObject* isabstract = PyObject_GetAttrString(obj, "__isabstractmethod__");
1336 if (isabstract == NULL) {
1337 PyErr_Clear();
1338 return 0;
1339 }
1340 Py_DECREF(isabstract);
durban 2011/06/20 22:40:40 It's probably not a good idea to call PyObject_IsT
1341 return PyObject_IsTrue(isabstract);
durban 2011/06/20 22:40:40 Also, PyObject_IsTrue returns an int. Its return v
dsdale24 2011/07/22 16:01:01 I don't understand the significance of this observ
durban 2011/07/23 12:47:22 You're returning an int from a function with a ret
1342 }
1343
1344 static PyObject *
1345 property_get__isabstractmethod__(PyObject *self, void *closure)
1346 {
1347 propertyobject *prop = (propertyobject *)self;
1348
1349 if (property_check_isabstract(prop, prop->prop_get))
1350 Py_RETURN_TRUE;
1351 if (property_check_isabstract(prop, prop->prop_set))
1352 Py_RETURN_TRUE;
1353 if (property_check_isabstract(prop, prop->prop_del)) {
1354 Py_RETURN_TRUE;
1355 }
1356 else {
1357 Py_RETURN_FALSE;
1358 }
1359 }
1360
1361 static PyGetSetDef property_getsetlist[] = {
1362 {"__isabstractmethod__",
1363 (getter)property_get__isabstractmethod__, NULL,
1364 NULL,
1365 NULL},
1366 {NULL} /* Sentinel */
1367 };
1328 1368
1329 PyDoc_STRVAR(property_doc, 1369 PyDoc_STRVAR(property_doc,
1330 "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"
1331 "\n" 1371 "\n"
1332 "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"
1333 "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"
1334 "attribute. Typical use is to define a managed attribute x:\n" 1374 "attribute. Typical use is to define a managed attribute x:\n"
1335 "class C(object):\n" 1375 "class C(object):\n"
1336 " def getx(self): return self._x\n" 1376 " def getx(self): return self._x\n"
1337 " def setx(self, value): self._x = value\n" 1377 " def setx(self, value): self._x = value\n"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 Py_TPFLAGS_BASETYPE, /* tp_flags */ 1424 Py_TPFLAGS_BASETYPE, /* tp_flags */
1385 property_doc, /* tp_doc */ 1425 property_doc, /* tp_doc */
1386 property_traverse, /* tp_traverse */ 1426 property_traverse, /* tp_traverse */
1387 0, /* tp_clear */ 1427 0, /* tp_clear */
1388 0, /* tp_richcompare */ 1428 0, /* tp_richcompare */
1389 0, /* tp_weaklistoffset */ 1429 0, /* tp_weaklistoffset */
1390 0, /* tp_iter */ 1430 0, /* tp_iter */
1391 0, /* tp_iternext */ 1431 0, /* tp_iternext */
1392 property_methods, /* tp_methods */ 1432 property_methods, /* tp_methods */
1393 property_members, /* tp_members */ 1433 property_members, /* tp_members */
1394 0, /* tp_getset */ 1434 property_getsetlist, /* tp_getset */
1395 0, /* tp_base */ 1435 0, /* tp_base */
1396 0, /* tp_dict */ 1436 0, /* tp_dict */
1397 property_descr_get, /* tp_descr_get */ 1437 property_descr_get, /* tp_descr_get */
1398 property_descr_set, /* tp_descr_set */ 1438 property_descr_set, /* tp_descr_set */
1399 0, /* tp_dictoffset */ 1439 0, /* tp_dictoffset */
1400 property_init, /* tp_init */ 1440 property_init, /* tp_init */
1401 PyType_GenericAlloc, /* tp_alloc */ 1441 PyType_GenericAlloc, /* tp_alloc */
1402 PyType_GenericNew, /* tp_new */ 1442 PyType_GenericNew, /* tp_new */
1403 PyObject_GC_Del, /* tp_free */ 1443 PyObject_GC_Del, /* tp_free */
1404 }; 1444 };
OLDNEW
« no previous file with comments | « Misc/NEWS ('k') | Objects/funcobject.c » ('j') | Objects/funcobject.c » ('J')

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