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

Side by Side Diff: Objects/funcobject.c

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