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

Side by Side Diff: Objects/funcobject.c

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 4 months 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_New(PyObject *code, PyObject *globals) 9 PyFunction_New(PyObject *code, PyObject *globals)
10 { 10 {
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (!_PyArg_NoKeywords("classmethod", kwds)) 765 if (!_PyArg_NoKeywords("classmethod", kwds))
766 return -1; 766 return -1;
767 Py_INCREF(callable); 767 Py_INCREF(callable);
768 cm->cm_callable = callable; 768 cm->cm_callable = callable;
769 return 0; 769 return 0;
770 } 770 }
771 771
772 static PyMemberDef cm_memberlist[] = { 772 static PyMemberDef cm_memberlist[] = {
773 {"__func__", T_OBJECT, offsetof(classmethod, cm_callable), READONLY}, 773 {"__func__", T_OBJECT, offsetof(classmethod, cm_callable), READONLY},
774 {NULL} /* Sentinel */ 774 {NULL} /* Sentinel */
775 };
776
777 static PyObject *
Benjamin Peterson 2011/11/29 02:45:54 Same comments as before.
dsdale24 2011/11/29 17:20:36 What comments would those be?
Benjamin Peterson 2011/11/29 17:27:46 On property_check_isabstract
778 cm_get__isabstractmethod__(classmethod *cm, void *closure)
779 {
780 if (cm->cm_callable == NULL)
781 Py_RETURN_FALSE;
782 PyObject* is_abstract = PyObject_GetAttrString(cm->cm_callable,
783 "__isabstractmethod__");
784 if (is_abstract == NULL) {
785 PyErr_Clear();
786 Py_RETURN_FALSE;
787 }
788 return is_abstract;
789 }
790
791 static PyGetSetDef cm_getsetlist[] = {
792 {"__isabstractmethod__",
793 (getter)cm_get__isabstractmethod__, NULL,
794 NULL,
795 NULL},
796 {NULL} /* Sentinel */
775 }; 797 };
776 798
777 PyDoc_STRVAR(classmethod_doc, 799 PyDoc_STRVAR(classmethod_doc,
778 "classmethod(function) -> method\n\ 800 "classmethod(function) -> method\n\
779 \n\ 801 \n\
780 Convert a function to be a class method.\n\ 802 Convert a function to be a class method.\n\
781 \n\ 803 \n\
782 A class method receives the class as implicit first argument,\n\ 804 A class method receives the class as implicit first argument,\n\
783 just like an instance method receives the instance.\n\ 805 just like an instance method receives the instance.\n\
784 To declare a class method, use this idiom:\n\ 806 To declare a class method, use this idiom:\n\
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, 840 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
819 classmethod_doc, /* tp_doc */ 841 classmethod_doc, /* tp_doc */
820 (traverseproc)cm_traverse, /* tp_traverse */ 842 (traverseproc)cm_traverse, /* tp_traverse */
821 (inquiry)cm_clear, /* tp_clear */ 843 (inquiry)cm_clear, /* tp_clear */
822 0, /* tp_richcompare */ 844 0, /* tp_richcompare */
823 0, /* tp_weaklistoffset */ 845 0, /* tp_weaklistoffset */
824 0, /* tp_iter */ 846 0, /* tp_iter */
825 0, /* tp_iternext */ 847 0, /* tp_iternext */
826 0, /* tp_methods */ 848 0, /* tp_methods */
827 cm_memberlist, /* tp_members */ 849 cm_memberlist, /* tp_members */
828 0, /* tp_getset */ 850 cm_getsetlist, /* tp_getset */
829 0, /* tp_base */ 851 0, /* tp_base */
830 0, /* tp_dict */ 852 0, /* tp_dict */
831 cm_descr_get, /* tp_descr_get */ 853 cm_descr_get, /* tp_descr_get */
832 0, /* tp_descr_set */ 854 0, /* tp_descr_set */
833 0, /* tp_dictoffset */ 855 0, /* tp_dictoffset */
834 cm_init, /* tp_init */ 856 cm_init, /* tp_init */
835 PyType_GenericAlloc, /* tp_alloc */ 857 PyType_GenericAlloc, /* tp_alloc */
836 PyType_GenericNew, /* tp_new */ 858 PyType_GenericNew, /* tp_new */
837 PyObject_GC_Del, /* tp_free */ 859 PyObject_GC_Del, /* tp_free */
838 }; 860 };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 if (!_PyArg_NoKeywords("staticmethod", kwds)) 942 if (!_PyArg_NoKeywords("staticmethod", kwds))
921 return -1; 943 return -1;
922 Py_INCREF(callable); 944 Py_INCREF(callable);
923 sm->sm_callable = callable; 945 sm->sm_callable = callable;
924 return 0; 946 return 0;
925 } 947 }
926 948
927 static PyMemberDef sm_memberlist[] = { 949 static PyMemberDef sm_memberlist[] = {
928 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY}, 950 {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
929 {NULL} /* Sentinel */ 951 {NULL} /* Sentinel */
952 };
953
954 static PyObject *
Benjamin Peterson 2011/11/29 02:45:54 And again.
955 sm_get__isabstractmethod__(staticmethod *sm, void *closure)
956 {
957 if (sm->sm_callable == NULL)
958 Py_RETURN_FALSE;
959 PyObject* is_abstract = PyObject_GetAttrString(sm->sm_callable,
960 "__isabstractmethod__");
961 if (is_abstract == NULL) {
962 PyErr_Clear();
963 Py_RETURN_FALSE;
964 }
965 return is_abstract;
966 }
967
968 static PyGetSetDef sm_getsetlist[] = {
969 {"__isabstractmethod__",
970 (getter)sm_get__isabstractmethod__, NULL,
971 NULL,
972 NULL},
973 {NULL} /* Sentinel */
930 }; 974 };
931 975
932 PyDoc_STRVAR(staticmethod_doc, 976 PyDoc_STRVAR(staticmethod_doc,
933 "staticmethod(function) -> method\n\ 977 "staticmethod(function) -> method\n\
934 \n\ 978 \n\
935 Convert a function to be a static method.\n\ 979 Convert a function to be a static method.\n\
936 \n\ 980 \n\
937 A static method does not receive an implicit first argument.\n\ 981 A static method does not receive an implicit first argument.\n\
938 To declare a static method, use this idiom:\n\ 982 To declare a static method, use this idiom:\n\
939 \n\ 983 \n\
(...skipping 30 matching lines...) Expand all
970 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, 1014 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
971 staticmethod_doc, /* tp_doc */ 1015 staticmethod_doc, /* tp_doc */
972 (traverseproc)sm_traverse, /* tp_traverse */ 1016 (traverseproc)sm_traverse, /* tp_traverse */
973 (inquiry)sm_clear, /* tp_clear */ 1017 (inquiry)sm_clear, /* tp_clear */
974 0, /* tp_richcompare */ 1018 0, /* tp_richcompare */
975 0, /* tp_weaklistoffset */ 1019 0, /* tp_weaklistoffset */
976 0, /* tp_iter */ 1020 0, /* tp_iter */
977 0, /* tp_iternext */ 1021 0, /* tp_iternext */
978 0, /* tp_methods */ 1022 0, /* tp_methods */
979 sm_memberlist, /* tp_members */ 1023 sm_memberlist, /* tp_members */
980 0, /* tp_getset */ 1024 sm_getsetlist, /* tp_getset */
981 0, /* tp_base */ 1025 0, /* tp_base */
982 0, /* tp_dict */ 1026 0, /* tp_dict */
983 sm_descr_get, /* tp_descr_get */ 1027 sm_descr_get, /* tp_descr_get */
984 0, /* tp_descr_set */ 1028 0, /* tp_descr_set */
985 0, /* tp_dictoffset */ 1029 0, /* tp_dictoffset */
986 sm_init, /* tp_init */ 1030 sm_init, /* tp_init */
987 PyType_GenericAlloc, /* tp_alloc */ 1031 PyType_GenericAlloc, /* tp_alloc */
988 PyType_GenericNew, /* tp_new */ 1032 PyType_GenericNew, /* tp_new */
989 PyObject_GC_Del, /* tp_free */ 1033 PyObject_GC_Del, /* tp_free */
990 }; 1034 };
991 1035
992 PyObject * 1036 PyObject *
993 PyStaticMethod_New(PyObject *callable) 1037 PyStaticMethod_New(PyObject *callable)
994 { 1038 {
995 staticmethod *sm = (staticmethod *) 1039 staticmethod *sm = (staticmethod *)
996 PyType_GenericAlloc(&PyStaticMethod_Type, 0); 1040 PyType_GenericAlloc(&PyStaticMethod_Type, 0);
997 if (sm != NULL) { 1041 if (sm != NULL) {
998 Py_INCREF(callable); 1042 Py_INCREF(callable);
999 sm->sm_callable = callable; 1043 sm->sm_callable = callable;
1000 } 1044 }
1001 return (PyObject *)sm; 1045 return (PyObject *)sm;
1002 } 1046 }
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+