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

Side by Side Diff: Objects/funcobject.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
« Objects/descrobject.c ('K') | « Objects/descrobject.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 if (!_PyArg_NoKeywords("classmethod", kwds)) 805 if (!_PyArg_NoKeywords("classmethod", kwds))
806 return -1; 806 return -1;
807 Py_INCREF(callable); 807 Py_INCREF(callable);
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 };
816
817 static PyObject *
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 {
820 if (cm->cm_callable == NULL)
821 Py_RETURN_FALSE;
822 _Py_IDENTIFIER(__isabstractmethod__);
823 PyObject* is_abstract = _PyObject_GetAttrId(cm->cm_callable,
824 &PyId___isabstractmethod__);
825 if (is_abstract == NULL) {
Benjamin Peterson 2011/12/04 22:56:35 Same comment about AttributeError as last time.
826 PyErr_Clear();
827 Py_RETURN_FALSE;
828 }
829 return is_abstract;
830 }
831
832 static PyGetSetDef cm_getsetlist[] = {
833 {"__isabstractmethod__",
834 (getter)cm_get__isabstractmethod__, NULL,
835 NULL,
836 NULL},
837 {NULL} /* Sentinel */
815 }; 838 };
816 839
817 PyDoc_STRVAR(classmethod_doc, 840 PyDoc_STRVAR(classmethod_doc,
818 "classmethod(function) -> method\n\ 841 "classmethod(function) -> method\n\
819 \n\ 842 \n\
820 Convert a function to be a class method.\n\ 843 Convert a function to be a class method.\n\
821 \n\ 844 \n\
822 A class method receives the class as implicit first argument,\n\ 845 A class method receives the class as implicit first argument,\n\
823 just like an instance method receives the instance.\n\ 846 just like an instance method receives the instance.\n\
824 To declare a class method, use this idiom:\n\ 847 To declare a class method, use this idiom:\n\
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, 881 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
859 classmethod_doc, /* tp_doc */ 882 classmethod_doc, /* tp_doc */
860 (traverseproc)cm_traverse, /* tp_traverse */ 883 (traverseproc)cm_traverse, /* tp_traverse */
861 (inquiry)cm_clear, /* tp_clear */ 884 (inquiry)cm_clear, /* tp_clear */
862 0, /* tp_richcompare */ 885 0, /* tp_richcompare */
863 0, /* tp_weaklistoffset */ 886 0, /* tp_weaklistoffset */
864 0, /* tp_iter */ 887 0, /* tp_iter */
865 0, /* tp_iternext */ 888 0, /* tp_iternext */
866 0, /* tp_methods */ 889 0, /* tp_methods */
867 cm_memberlist, /* tp_members */ 890 cm_memberlist, /* tp_members */
868 0, /* tp_getset */ 891 cm_getsetlist, /* tp_getset */
869 0, /* tp_base */ 892 0, /* tp_base */
870 0, /* tp_dict */ 893 0, /* tp_dict */
871 cm_descr_get, /* tp_descr_get */ 894 cm_descr_get, /* tp_descr_get */
872 0, /* tp_descr_set */ 895 0, /* tp_descr_set */
873 0, /* tp_dictoffset */ 896 0, /* tp_dictoffset */
874 cm_init, /* tp_init */ 897 cm_init, /* tp_init */
875 PyType_GenericAlloc, /* tp_alloc */ 898 PyType_GenericAlloc, /* tp_alloc */
876 PyType_GenericNew, /* tp_new */ 899 PyType_GenericNew, /* tp_new */
877 PyObject_GC_Del, /* tp_free */ 900 PyObject_GC_Del, /* tp_free */
878 }; 901 };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 if (!_PyArg_NoKeywords("staticmethod", kwds)) 983 if (!_PyArg_NoKeywords("staticmethod", kwds))
961 return -1; 984 return -1;
962 Py_INCREF(callable); 985 Py_INCREF(callable);
963 sm->sm_callable = callable; 986 sm->sm_callable = callable;
964 return 0; 987 return 0;
965 } 988 }
966 989
967 static PyMemberDef sm_memberlist[] = { 990 static PyMemberDef sm_memberlist[] = {
968 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY}, 991 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
969 {NULL} /* Sentinel */ 992 {NULL} /* Sentinel */
993 };
994
995 static PyObject *
996 sm_get__isabstractmethod__(staticmethod *sm, void *closure)
997 {
998 if (sm->sm_callable == NULL)
999 Py_RETURN_FALSE;
1000 _Py_IDENTIFIER(__isabstractmethod__);
1001 PyObject* is_abstract = _PyObject_GetAttrId(sm->sm_callable,
1002 &PyId___isabstractmethod__);
1003 if (is_abstract == NULL) {
1004 PyErr_Clear();
1005 Py_RETURN_FALSE;
1006 }
1007 return is_abstract;
1008 }
1009
1010 static PyGetSetDef sm_getsetlist[] = {
1011 {"__isabstractmethod__",
1012 (getter)sm_get__isabstractmethod__, NULL,
1013 NULL,
1014 NULL},
1015 {NULL} /* Sentinel */
970 }; 1016 };
971 1017
972 PyDoc_STRVAR(staticmethod_doc, 1018 PyDoc_STRVAR(staticmethod_doc,
973 "staticmethod(function) -> method\n\ 1019 "staticmethod(function) -> method\n\
974 \n\ 1020 \n\
975 Convert a function to be a static method.\n\ 1021 Convert a function to be a static method.\n\
976 \n\ 1022 \n\
977 A static method does not receive an implicit first argument.\n\ 1023 A static method does not receive an implicit first argument.\n\
978 To declare a static method, use this idiom:\n\ 1024 To declare a static method, use this idiom:\n\
979 \n\ 1025 \n\
(...skipping 30 matching lines...) Expand all
1010 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, 1056 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1011 staticmethod_doc, /* tp_doc */ 1057 staticmethod_doc, /* tp_doc */
1012 (traverseproc)sm_traverse, /* tp_traverse */ 1058 (traverseproc)sm_traverse, /* tp_traverse */
1013 (inquiry)sm_clear, /* tp_clear */ 1059 (inquiry)sm_clear, /* tp_clear */
1014 0, /* tp_richcompare */ 1060 0, /* tp_richcompare */
1015 0, /* tp_weaklistoffset */ 1061 0, /* tp_weaklistoffset */
1016 0, /* tp_iter */ 1062 0, /* tp_iter */
1017 0, /* tp_iternext */ 1063 0, /* tp_iternext */
1018 0, /* tp_methods */ 1064 0, /* tp_methods */
1019 sm_memberlist, /* tp_members */ 1065 sm_memberlist, /* tp_members */
1020 0, /* tp_getset */ 1066 sm_getsetlist, /* tp_getset */
1021 0, /* tp_base */ 1067 0, /* tp_base */
1022 0, /* tp_dict */ 1068 0, /* tp_dict */
1023 sm_descr_get, /* tp_descr_get */ 1069 sm_descr_get, /* tp_descr_get */
1024 0, /* tp_descr_set */ 1070 0, /* tp_descr_set */
1025 0, /* tp_dictoffset */ 1071 0, /* tp_dictoffset */
1026 sm_init, /* tp_init */ 1072 sm_init, /* tp_init */
1027 PyType_GenericAlloc, /* tp_alloc */ 1073 PyType_GenericAlloc, /* tp_alloc */
1028 PyType_GenericNew, /* tp_new */ 1074 PyType_GenericNew, /* tp_new */
1029 PyObject_GC_Del, /* tp_free */ 1075 PyObject_GC_Del, /* tp_free */
1030 }; 1076 };
1031 1077
1032 PyObject * 1078 PyObject *
1033 PyStaticMethod_New(PyObject *callable) 1079 PyStaticMethod_New(PyObject *callable)
1034 { 1080 {
1035 staticmethod *sm = (staticmethod *) 1081 staticmethod *sm = (staticmethod *)
1036 PyType_GenericAlloc(&PyStaticMethod_Type, 0); 1082 PyType_GenericAlloc(&PyStaticMethod_Type, 0);
1037 if (sm != NULL) { 1083 if (sm != NULL) {
1038 Py_INCREF(callable); 1084 Py_INCREF(callable);
1039 sm->sm_callable = callable; 1085 sm->sm_callable = callable;
1040 } 1086 }
1041 return (PyObject *)sm; 1087 return (PyObject *)sm;
1042 } 1088 }
OLDNEW
« Objects/descrobject.c ('K') | « Objects/descrobject.c ('k') | no next file » | no next file with comments »

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