22/* Function object implementation */
33
44#include "Python.h"
5+ #include "pycore_ceval.h" // _PyEval_BuiltinsFromGlobals()
56#include "pycore_dict.h" // _Py_INCREF_DICT()
67#include "pycore_long.h" // _PyLong_GetOne()
78#include "pycore_modsupport.h" // _PyArg_NoKeywords()
@@ -591,8 +592,9 @@ class function "PyFunctionObject *" "&PyFunction_Type"
591592#include "clinic/funcobject.c.h"
592593
593594static PyObject *
594- func_get_code (PyFunctionObject * op , void * Py_UNUSED (ignored ))
595+ func_get_code (PyObject * self , void * Py_UNUSED (ignored ))
595596{
597+ PyFunctionObject * op = _PyFunction_CAST (self );
596598 if (PySys_Audit ("object.__getattr__" , "Os" , op , "__code__" ) < 0 ) {
597599 return NULL ;
598600 }
@@ -601,8 +603,9 @@ func_get_code(PyFunctionObject *op, void *Py_UNUSED(ignored))
601603}
602604
603605static int
604- func_set_code (PyFunctionObject * op , PyObject * value , void * Py_UNUSED (ignored ))
606+ func_set_code (PyObject * self , PyObject * value , void * Py_UNUSED (ignored ))
605607{
608+ PyFunctionObject * op = _PyFunction_CAST (self );
606609 Py_ssize_t nclosure ;
607610 int nfree ;
608611
@@ -651,14 +654,16 @@ func_set_code(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored))
651654}
652655
653656static PyObject *
654- func_get_name (PyFunctionObject * op , void * Py_UNUSED (ignored ))
657+ func_get_name (PyObject * self , void * Py_UNUSED (ignored ))
655658{
659+ PyFunctionObject * op = _PyFunction_CAST (self );
656660 return Py_NewRef (op -> func_name );
657661}
658662
659663static int
660- func_set_name (PyFunctionObject * op , PyObject * value , void * Py_UNUSED (ignored ))
664+ func_set_name (PyObject * self , PyObject * value , void * Py_UNUSED (ignored ))
661665{
666+ PyFunctionObject * op = _PyFunction_CAST (self );
662667 /* Not legal to del f.func_name or to set it to anything
663668 * other than a string object. */
664669 if (value == NULL || !PyUnicode_Check (value )) {
@@ -671,14 +676,16 @@ func_set_name(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored))
671676}
672677
673678static PyObject *
674- func_get_qualname (PyFunctionObject * op , void * Py_UNUSED (ignored ))
679+ func_get_qualname (PyObject * self , void * Py_UNUSED (ignored ))
675680{
681+ PyFunctionObject * op = _PyFunction_CAST (self );
676682 return Py_NewRef (op -> func_qualname );
677683}
678684
679685static int
680- func_set_qualname (PyFunctionObject * op , PyObject * value , void * Py_UNUSED (ignored ))
686+ func_set_qualname (PyObject * self , PyObject * value , void * Py_UNUSED (ignored ))
681687{
688+ PyFunctionObject * op = _PyFunction_CAST (self );
682689 /* Not legal to del f.__qualname__ or to set it to anything
683690 * other than a string object. */
684691 if (value == NULL || !PyUnicode_Check (value )) {
@@ -691,8 +698,9 @@ func_set_qualname(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored
691698}
692699
693700static PyObject *
694- func_get_defaults (PyFunctionObject * op , void * Py_UNUSED (ignored ))
701+ func_get_defaults (PyObject * self , void * Py_UNUSED (ignored ))
695702{
703+ PyFunctionObject * op = _PyFunction_CAST (self );
696704 if (PySys_Audit ("object.__getattr__" , "Os" , op , "__defaults__" ) < 0 ) {
697705 return NULL ;
698706 }
@@ -703,8 +711,9 @@ func_get_defaults(PyFunctionObject *op, void *Py_UNUSED(ignored))
703711}
704712
705713static int
706- func_set_defaults (PyFunctionObject * op , PyObject * value , void * Py_UNUSED (ignored ))
714+ func_set_defaults (PyObject * self , PyObject * value , void * Py_UNUSED (ignored ))
707715{
716+ PyFunctionObject * op = _PyFunction_CAST (self );
708717 /* Legal to del f.func_defaults.
709718 * Can only set func_defaults to NULL or a tuple. */
710719 if (value == Py_None )
@@ -731,8 +740,9 @@ func_set_defaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored
731740}
732741
733742static PyObject *
734- func_get_kwdefaults (PyFunctionObject * op , void * Py_UNUSED (ignored ))
743+ func_get_kwdefaults (PyObject * self , void * Py_UNUSED (ignored ))
735744{
745+ PyFunctionObject * op = _PyFunction_CAST (self );
736746 if (PySys_Audit ("object.__getattr__" , "Os" ,
737747 op , "__kwdefaults__" ) < 0 ) {
738748 return NULL ;
@@ -744,8 +754,9 @@ func_get_kwdefaults(PyFunctionObject *op, void *Py_UNUSED(ignored))
744754}
745755
746756static int
747- func_set_kwdefaults (PyFunctionObject * op , PyObject * value , void * Py_UNUSED (ignored ))
757+ func_set_kwdefaults (PyObject * self , PyObject * value , void * Py_UNUSED (ignored ))
748758{
759+ PyFunctionObject * op = _PyFunction_CAST (self );
749760 if (value == Py_None )
750761 value = NULL ;
751762 /* Legal to del f.func_kwdefaults.
@@ -771,54 +782,6 @@ func_set_kwdefaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignor
771782 return 0 ;
772783}
773784
774- /*[clinic input]
775- @critical_section
776- @getter
777- function.__annotate__
778-
779- Get the code object for a function.
780- [clinic start generated code]*/
781-
782- static PyObject *
783- function___annotate___get_impl (PyFunctionObject * self )
784- /*[clinic end generated code: output=5ec7219ff2bda9e6 input=7f3db11e3c3329f3]*/
785- {
786- if (self -> func_annotate == NULL ) {
787- Py_RETURN_NONE ;
788- }
789- return Py_NewRef (self -> func_annotate );
790- }
791-
792- /*[clinic input]
793- @critical_section
794- @setter
795- function.__annotate__
796- [clinic start generated code]*/
797-
798- static int
799- function___annotate___set_impl (PyFunctionObject * self , PyObject * value )
800- /*[clinic end generated code: output=05b7dfc07ada66cd input=eb6225e358d97448]*/
801- {
802- if (value == NULL ) {
803- PyErr_SetString (PyExc_TypeError ,
804- "__annotate__ cannot be deleted" );
805- return -1 ;
806- }
807- if (Py_IsNone (value )) {
808- Py_XSETREF (self -> func_annotate , value );
809- return 0 ;
810- }
811- else if (PyCallable_Check (value )) {
812- Py_XSETREF (self -> func_annotate , Py_XNewRef (value ));
813- Py_CLEAR (self -> func_annotations );
814- return 0 ;
815- }
816- else {
817- PyErr_SetString (PyExc_TypeError ,
818- "__annotate__ must be callable or None" );
819- return -1 ;
820- }
821- }
822785
823786/*[clinic input]
824787@critical_section
@@ -833,8 +796,7 @@ function___annotations___get_impl(PyFunctionObject *self)
833796/*[clinic end generated code: output=a4cf4c884c934cbb input=92643d7186c1ad0c]*/
834797{
835798 PyObject * d = NULL ;
836- if (self -> func_annotations == NULL &&
837- (self -> func_annotate == NULL || !PyCallable_Check (self -> func_annotate ))) {
799+ if (self -> func_annotations == NULL ) {
838800 self -> func_annotations = PyDict_New ();
839801 if (self -> func_annotations == NULL )
840802 return NULL ;
@@ -864,7 +826,6 @@ function___annotations___set_impl(PyFunctionObject *self, PyObject *value)
864826 return -1 ;
865827 }
866828 Py_XSETREF (self -> func_annotations , Py_XNewRef (value ));
867- Py_CLEAR (self -> func_annotate );
868829 return 0 ;
869830}
870831
@@ -925,7 +886,6 @@ static PyGetSetDef func_getsetlist[] = {
925886 {"__defaults__" , func_get_defaults , func_set_defaults },
926887 {"__kwdefaults__" , func_get_kwdefaults , func_set_kwdefaults },
927888 FUNCTION___ANNOTATIONS___GETSETDEF
928- FUNCTION___ANNOTATE___GETSETDEF
929889 {"__dict__" , PyObject_GenericGetDict , PyObject_GenericSetDict },
930890 {"__name__" , func_get_name , func_set_name },
931891 {"__qualname__" , func_get_qualname , func_set_qualname },
0 commit comments