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

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

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