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

Delta Between Two Patch Sets: Objects/funcobject.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 | « Objects/descrobject.c ('k') | Objects/object.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 1
2 /* Function object implementation */ 2 /* Function object implementation */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 #include "code.h" 5 #include "code.h"
6 #include "structmember.h" 6 #include "structmember.h"
7 7
8 PyObject * 8 PyObject *
9 PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname ) 9 PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname )
10 { 10 {
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 cm->cm_callable = callable; 808 cm->cm_callable = callable;
809 return 0; 809 return 0;
810 } 810 }
811 811
812 static PyMemberDef cm_memberlist[] = { 812 static PyMemberDef cm_memberlist[] = {
813 {"__func__", T_OBJECT, offsetof(classmethod, cm_callable), READONLY}, 813 {"__func__", T_OBJECT, offsetof(classmethod, cm_callable), READONLY},
814 {NULL} /* Sentinel */ 814 {NULL} /* Sentinel */
815 }; 815 };
816 816
817 static PyObject * 817 static PyObject *
818 cm_get__isabstractmethod__(classmethod *cm, void *closure) 818 cm_get___isabstractmethod__(classmethod *cm, void *closure)
Benjamin Peterson 2011/12/04 22:56:35 Same comments as property_check_isabstract
dsdale24 2011/12/05 15:59:23 Will address in next patch.
819 { 819 {
820 if (cm->cm_callable == NULL) 820 int res = _PyObject_IsAbstract(cm->cm_callable);
821 Py_RETURN_FALSE; 821 if (res == -1) {
822 _Py_IDENTIFIER(__isabstractmethod__); 822 return NULL;
823 PyObject* is_abstract = _PyObject_GetAttrId(cm->cm_callable, 823 }
824 &PyId___isabstractmethod__); 824 else if (res) {
825 if (is_abstract == NULL) { 825 Py_RETURN_TRUE;
Benjamin Peterson 2011/12/04 22:56:35 Same comment about AttributeError as last time.
826 PyErr_Clear(); 826 }
827 Py_RETURN_FALSE; 827 Py_RETURN_FALSE;
828 }
829 return is_abstract;
830 } 828 }
831 829
832 static PyGetSetDef cm_getsetlist[] = { 830 static PyGetSetDef cm_getsetlist[] = {
833 {"__isabstractmethod__", 831 {"__isabstractmethod__",
834 (getter)cm_get__isabstractmethod__, NULL, 832 (getter)cm_get___isabstractmethod__, NULL,
835 NULL, 833 NULL,
836 NULL}, 834 NULL},
837 {NULL} /* Sentinel */ 835 {NULL} /* Sentinel */
838 }; 836 };
839 837
840 PyDoc_STRVAR(classmethod_doc, 838 PyDoc_STRVAR(classmethod_doc,
841 "classmethod(function) -> method\n\ 839 "classmethod(function) -> method\n\
842 \n\ 840 \n\
843 Convert a function to be a class method.\n\ 841 Convert a function to be a class method.\n\
844 \n\ 842 \n\
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 sm->sm_callable = callable; 984 sm->sm_callable = callable;
987 return 0; 985 return 0;
988 } 986 }
989 987
990 static PyMemberDef sm_memberlist[] = { 988 static PyMemberDef sm_memberlist[] = {
991 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY}, 989 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
992 {NULL} /* Sentinel */ 990 {NULL} /* Sentinel */
993 }; 991 };
994 992
995 static PyObject * 993 static PyObject *
996 sm_get__isabstractmethod__(staticmethod *sm, void *closure) 994 sm_get___isabstractmethod__(staticmethod *sm, void *closure)
997 { 995 {
998 if (sm->sm_callable == NULL) 996 int res = _PyObject_IsAbstract(sm->sm_callable);
999 Py_RETURN_FALSE; 997 if (res == -1) {
1000 _Py_IDENTIFIER(__isabstractmethod__); 998 return NULL;
1001 PyObject* is_abstract = _PyObject_GetAttrId(sm->sm_callable, 999 }
1002 &PyId___isabstractmethod__); 1000 else if (res) {
1003 if (is_abstract == NULL) { 1001 Py_RETURN_TRUE;
1004 PyErr_Clear(); 1002 }
1005 Py_RETURN_FALSE; 1003 Py_RETURN_FALSE;
1006 }
1007 return is_abstract;
1008 } 1004 }
1009 1005
1010 static PyGetSetDef sm_getsetlist[] = { 1006 static PyGetSetDef sm_getsetlist[] = {
1011 {"__isabstractmethod__", 1007 {"__isabstractmethod__",
1012 (getter)sm_get__isabstractmethod__, NULL, 1008 (getter)sm_get___isabstractmethod__, NULL,
1013 NULL, 1009 NULL,
1014 NULL}, 1010 NULL},
1015 {NULL} /* Sentinel */ 1011 {NULL} /* Sentinel */
1016 }; 1012 };
1017 1013
1018 PyDoc_STRVAR(staticmethod_doc, 1014 PyDoc_STRVAR(staticmethod_doc,
1019 "staticmethod(function) -> method\n\ 1015 "staticmethod(function) -> method\n\
1020 \n\ 1016 \n\
1021 Convert a function to be a static method.\n\ 1017 Convert a function to be a static method.\n\
1022 \n\ 1018 \n\
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 PyStaticMethod_New(PyObject *callable) 1075 PyStaticMethod_New(PyObject *callable)
1080 { 1076 {
1081 staticmethod *sm = (staticmethod *) 1077 staticmethod *sm = (staticmethod *)
1082 PyType_GenericAlloc(&PyStaticMethod_Type, 0); 1078 PyType_GenericAlloc(&PyStaticMethod_Type, 0);
1083 if (sm != NULL) { 1079 if (sm != NULL) {
1084 Py_INCREF(callable); 1080 Py_INCREF(callable);
1085 sm->sm_callable = callable; 1081 sm->sm_callable = callable;
1086 } 1082 }
1087 return (PyObject *)sm; 1083 return (PyObject *)sm;
1088 } 1084 }
LEFTRIGHT

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