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

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
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)
819 {
820 int res = _PyObject_IsAbstract(cm->cm_callable);
821 if (res == -1)
Nick Coghlan 2011/12/06 09:14:01 Always use the braces when there are multiple clau
822 return NULL;
823 else if (res)
824 Py_RETURN_TRUE;
825
826 Py_RETURN_FALSE;
827 }
828
829 static PyGetSetDef cm_getsetlist[] = {
830 {"__isabstractmethod__",
831 (getter)cm_get___isabstractmethod__, NULL,
832 NULL,
833 NULL},
834 {NULL} /* Sentinel */
815 }; 835 };
816 836
817 PyDoc_STRVAR(classmethod_doc, 837 PyDoc_STRVAR(classmethod_doc,
818 "classmethod(function) -> method\n\ 838 "classmethod(function) -> method\n\
819 \n\ 839 \n\
820 Convert a function to be a class method.\n\ 840 Convert a function to be a class method.\n\
821 \n\ 841 \n\
822 A class method receives the class as implicit first argument,\n\ 842 A class method receives the class as implicit first argument,\n\
823 just like an instance method receives the instance.\n\ 843 just like an instance method receives the instance.\n\
824 To declare a class method, use this idiom:\n\ 844 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, 878 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
859 classmethod_doc, /* tp_doc */ 879 classmethod_doc, /* tp_doc */
860 (traverseproc)cm_traverse, /* tp_traverse */ 880 (traverseproc)cm_traverse, /* tp_traverse */
861 (inquiry)cm_clear, /* tp_clear */ 881 (inquiry)cm_clear, /* tp_clear */
862 0, /* tp_richcompare */ 882 0, /* tp_richcompare */
863 0, /* tp_weaklistoffset */ 883 0, /* tp_weaklistoffset */
864 0, /* tp_iter */ 884 0, /* tp_iter */
865 0, /* tp_iternext */ 885 0, /* tp_iternext */
866 0, /* tp_methods */ 886 0, /* tp_methods */
867 cm_memberlist, /* tp_members */ 887 cm_memberlist, /* tp_members */
868 0, /* tp_getset */ 888 cm_getsetlist, /* tp_getset */
869 0, /* tp_base */ 889 0, /* tp_base */
870 0, /* tp_dict */ 890 0, /* tp_dict */
871 cm_descr_get, /* tp_descr_get */ 891 cm_descr_get, /* tp_descr_get */
872 0, /* tp_descr_set */ 892 0, /* tp_descr_set */
873 0, /* tp_dictoffset */ 893 0, /* tp_dictoffset */
874 cm_init, /* tp_init */ 894 cm_init, /* tp_init */
875 PyType_GenericAlloc, /* tp_alloc */ 895 PyType_GenericAlloc, /* tp_alloc */
876 PyType_GenericNew, /* tp_new */ 896 PyType_GenericNew, /* tp_new */
877 PyObject_GC_Del, /* tp_free */ 897 PyObject_GC_Del, /* tp_free */
878 }; 898 };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 if (!_PyArg_NoKeywords("staticmethod", kwds)) 980 if (!_PyArg_NoKeywords("staticmethod", kwds))
961 return -1; 981 return -1;
962 Py_INCREF(callable); 982 Py_INCREF(callable);
963 sm->sm_callable = callable; 983 sm->sm_callable = callable;
964 return 0; 984 return 0;
965 } 985 }
966 986
967 static PyMemberDef sm_memberlist[] = { 987 static PyMemberDef sm_memberlist[] = {
968 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY}, 988 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
969 {NULL} /* Sentinel */ 989 {NULL} /* Sentinel */
990 };
991
992 static PyObject *
993 sm_get___isabstractmethod__(staticmethod *sm, void *closure)
994 {
995 int res = _PyObject_IsAbstract(sm->sm_callable);
996 if (res == -1)
Nick Coghlan 2011/12/06 09:14:01 Braces
997 return NULL;
998 else if (res)
999 Py_RETURN_TRUE;
1000
1001 Py_RETURN_FALSE;
1002 }
1003
1004 static PyGetSetDef sm_getsetlist[] = {
1005 {"__isabstractmethod__",
1006 (getter)sm_get___isabstractmethod__, NULL,
1007 NULL,
1008 NULL},
1009 {NULL} /* Sentinel */
970 }; 1010 };
971 1011
972 PyDoc_STRVAR(staticmethod_doc, 1012 PyDoc_STRVAR(staticmethod_doc,
973 "staticmethod(function) -> method\n\ 1013 "staticmethod(function) -> method\n\
974 \n\ 1014 \n\
975 Convert a function to be a static method.\n\ 1015 Convert a function to be a static method.\n\
976 \n\ 1016 \n\
977 A static method does not receive an implicit first argument.\n\ 1017 A static method does not receive an implicit first argument.\n\
978 To declare a static method, use this idiom:\n\ 1018 To declare a static method, use this idiom:\n\
979 \n\ 1019 \n\
(...skipping 30 matching lines...) Expand all
1010 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, 1050 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1011 staticmethod_doc, /* tp_doc */ 1051 staticmethod_doc, /* tp_doc */
1012 (traverseproc)sm_traverse, /* tp_traverse */ 1052 (traverseproc)sm_traverse, /* tp_traverse */
1013 (inquiry)sm_clear, /* tp_clear */ 1053 (inquiry)sm_clear, /* tp_clear */
1014 0, /* tp_richcompare */ 1054 0, /* tp_richcompare */
1015 0, /* tp_weaklistoffset */ 1055 0, /* tp_weaklistoffset */
1016 0, /* tp_iter */ 1056 0, /* tp_iter */
1017 0, /* tp_iternext */ 1057 0, /* tp_iternext */
1018 0, /* tp_methods */ 1058 0, /* tp_methods */
1019 sm_memberlist, /* tp_members */ 1059 sm_memberlist, /* tp_members */
1020 0, /* tp_getset */ 1060 sm_getsetlist, /* tp_getset */
1021 0, /* tp_base */ 1061 0, /* tp_base */
1022 0, /* tp_dict */ 1062 0, /* tp_dict */
1023 sm_descr_get, /* tp_descr_get */ 1063 sm_descr_get, /* tp_descr_get */
1024 0, /* tp_descr_set */ 1064 0, /* tp_descr_set */
1025 0, /* tp_dictoffset */ 1065 0, /* tp_dictoffset */
1026 sm_init, /* tp_init */ 1066 sm_init, /* tp_init */
1027 PyType_GenericAlloc, /* tp_alloc */ 1067 PyType_GenericAlloc, /* tp_alloc */
1028 PyType_GenericNew, /* tp_new */ 1068 PyType_GenericNew, /* tp_new */
1029 PyObject_GC_Del, /* tp_free */ 1069 PyObject_GC_Del, /* tp_free */
1030 }; 1070 };
1031 1071
1032 PyObject * 1072 PyObject *
1033 PyStaticMethod_New(PyObject *callable) 1073 PyStaticMethod_New(PyObject *callable)
1034 { 1074 {
1035 staticmethod *sm = (staticmethod *) 1075 staticmethod *sm = (staticmethod *)
1036 PyType_GenericAlloc(&PyStaticMethod_Type, 0); 1076 PyType_GenericAlloc(&PyStaticMethod_Type, 0);
1037 if (sm != NULL) { 1077 if (sm != NULL) {
1038 Py_INCREF(callable); 1078 Py_INCREF(callable);
1039 sm->sm_callable = callable; 1079 sm->sm_callable = callable;
1040 } 1080 }
1041 return (PyObject *)sm; 1081 return (PyObject *)sm;
1042 } 1082 }
OLDNEW
« Objects/descrobject.c ('K') | « Objects/descrobject.c ('k') | Objects/object.c » ('j') | no next file with comments »

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