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

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
« no previous file with comments | « Misc/ACKS ('k') | Objects/funcobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 PyObject *
1333 property_get___isabstractmethod__(propertyobject *prop, void *closure)
1334 {
1335 int res = _PyObject_IsAbstract(prop->prop_get);
1336 if (res == -1) {
1337 return NULL;
1338 }
1339 else if (res) {
1340 Py_RETURN_TRUE;
1341 }
1342
1343 res = _PyObject_IsAbstract(prop->prop_set);
1344 if (res == -1) {
1345 return NULL;
1346 }
1347 else if (res) {
1348 Py_RETURN_TRUE;
1349 }
1350
1351 res = _PyObject_IsAbstract(prop->prop_del);
1352 if (res == -1) {
1353 return NULL;
1354 }
1355 else if (res) {
1356 Py_RETURN_TRUE;
1357 }
1358 Py_RETURN_FALSE;
1359 }
1360
1361 static PyGetSetDef property_getsetlist[] = {
1362 {"__isabstractmethod__",
1363 (getter)property_get___isabstractmethod__, NULL,
1364 NULL,
1365 NULL},
1366 {NULL} /* Sentinel */
1367 };
1331 1368
1332 PyDoc_STRVAR(property_doc, 1369 PyDoc_STRVAR(property_doc,
1333 "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"
1334 "\n" 1371 "\n"
1335 "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"
1336 "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"
1337 "attribute. Typical use is to define a managed attribute x:\n" 1374 "attribute. Typical use is to define a managed attribute x:\n"
1338 "class C(object):\n" 1375 "class C(object):\n"
1339 " def getx(self): return self._x\n" 1376 " def getx(self): return self._x\n"
1340 " 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
1387 Py_TPFLAGS_BASETYPE, /* tp_flags */ 1424 Py_TPFLAGS_BASETYPE, /* tp_flags */
1388 property_doc, /* tp_doc */ 1425 property_doc, /* tp_doc */
1389 property_traverse, /* tp_traverse */ 1426 property_traverse, /* tp_traverse */
1390 0, /* tp_clear */ 1427 0, /* tp_clear */
1391 0, /* tp_richcompare */ 1428 0, /* tp_richcompare */
1392 0, /* tp_weaklistoffset */ 1429 0, /* tp_weaklistoffset */
1393 0, /* tp_iter */ 1430 0, /* tp_iter */
1394 0, /* tp_iternext */ 1431 0, /* tp_iternext */
1395 property_methods, /* tp_methods */ 1432 property_methods, /* tp_methods */
1396 property_members, /* tp_members */ 1433 property_members, /* tp_members */
1397 0, /* tp_getset */ 1434 property_getsetlist, /* tp_getset */
1398 0, /* tp_base */ 1435 0, /* tp_base */
1399 0, /* tp_dict */ 1436 0, /* tp_dict */
1400 property_descr_get, /* tp_descr_get */ 1437 property_descr_get, /* tp_descr_get */
1401 property_descr_set, /* tp_descr_set */ 1438 property_descr_set, /* tp_descr_set */
1402 0, /* tp_dictoffset */ 1439 0, /* tp_dictoffset */
1403 property_init, /* tp_init */ 1440 property_init, /* tp_init */
1404 PyType_GenericAlloc, /* tp_alloc */ 1441 PyType_GenericAlloc, /* tp_alloc */
1405 PyType_GenericNew, /* tp_new */ 1442 PyType_GenericNew, /* tp_new */
1406 PyObject_GC_Del, /* tp_free */ 1443 PyObject_GC_Del, /* tp_free */
1407 }; 1444 };
OLDNEW
« no previous file with comments | « Misc/ACKS ('k') | Objects/funcobject.c » ('j') | no next file with comments »

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