2
2
/* Function object implementation */
3
3
4
4
#include "Python.h"
5
+ #include "pycore_ceval.h" // _PyEval_BuiltinsFromGlobals()
5
6
#include "pycore_dict.h" // _Py_INCREF_DICT()
6
7
#include "pycore_long.h" // _PyLong_GetOne()
7
8
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
@@ -591,8 +592,9 @@ class function "PyFunctionObject *" "&PyFunction_Type"
591
592
#include "clinic/funcobject.c.h"
592
593
593
594
static PyObject *
594
- func_get_code (PyFunctionObject * op , void * Py_UNUSED (ignored ))
595
+ func_get_code (PyObject * self , void * Py_UNUSED (ignored ))
595
596
{
597
+ PyFunctionObject * op = _PyFunction_CAST (self );
596
598
if (PySys_Audit ("object.__getattr__" , "Os" , op , "__code__" ) < 0 ) {
597
599
return NULL ;
598
600
}
@@ -601,8 +603,9 @@ func_get_code(PyFunctionObject *op, void *Py_UNUSED(ignored))
601
603
}
602
604
603
605
static 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 ))
605
607
{
608
+ PyFunctionObject * op = _PyFunction_CAST (self );
606
609
Py_ssize_t nclosure ;
607
610
int nfree ;
608
611
@@ -651,14 +654,16 @@ func_set_code(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored))
651
654
}
652
655
653
656
static PyObject *
654
- func_get_name (PyFunctionObject * op , void * Py_UNUSED (ignored ))
657
+ func_get_name (PyObject * self , void * Py_UNUSED (ignored ))
655
658
{
659
+ PyFunctionObject * op = _PyFunction_CAST (self );
656
660
return Py_NewRef (op -> func_name );
657
661
}
658
662
659
663
static 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 ))
661
665
{
666
+ PyFunctionObject * op = _PyFunction_CAST (self );
662
667
/* Not legal to del f.func_name or to set it to anything
663
668
* other than a string object. */
664
669
if (value == NULL || !PyUnicode_Check (value )) {
@@ -671,14 +676,16 @@ func_set_name(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored))
671
676
}
672
677
673
678
static PyObject *
674
- func_get_qualname (PyFunctionObject * op , void * Py_UNUSED (ignored ))
679
+ func_get_qualname (PyObject * self , void * Py_UNUSED (ignored ))
675
680
{
681
+ PyFunctionObject * op = _PyFunction_CAST (self );
676
682
return Py_NewRef (op -> func_qualname );
677
683
}
678
684
679
685
static 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 ))
681
687
{
688
+ PyFunctionObject * op = _PyFunction_CAST (self );
682
689
/* Not legal to del f.__qualname__ or to set it to anything
683
690
* other than a string object. */
684
691
if (value == NULL || !PyUnicode_Check (value )) {
@@ -691,8 +698,9 @@ func_set_qualname(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored
691
698
}
692
699
693
700
static PyObject *
694
- func_get_defaults (PyFunctionObject * op , void * Py_UNUSED (ignored ))
701
+ func_get_defaults (PyObject * self , void * Py_UNUSED (ignored ))
695
702
{
703
+ PyFunctionObject * op = _PyFunction_CAST (self );
696
704
if (PySys_Audit ("object.__getattr__" , "Os" , op , "__defaults__" ) < 0 ) {
697
705
return NULL ;
698
706
}
@@ -703,8 +711,9 @@ func_get_defaults(PyFunctionObject *op, void *Py_UNUSED(ignored))
703
711
}
704
712
705
713
static 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 ))
707
715
{
716
+ PyFunctionObject * op = _PyFunction_CAST (self );
708
717
/* Legal to del f.func_defaults.
709
718
* Can only set func_defaults to NULL or a tuple. */
710
719
if (value == Py_None )
@@ -731,8 +740,9 @@ func_set_defaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored
731
740
}
732
741
733
742
static PyObject *
734
- func_get_kwdefaults (PyFunctionObject * op , void * Py_UNUSED (ignored ))
743
+ func_get_kwdefaults (PyObject * self , void * Py_UNUSED (ignored ))
735
744
{
745
+ PyFunctionObject * op = _PyFunction_CAST (self );
736
746
if (PySys_Audit ("object.__getattr__" , "Os" ,
737
747
op , "__kwdefaults__" ) < 0 ) {
738
748
return NULL ;
@@ -744,8 +754,9 @@ func_get_kwdefaults(PyFunctionObject *op, void *Py_UNUSED(ignored))
744
754
}
745
755
746
756
static 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 ))
748
758
{
759
+ PyFunctionObject * op = _PyFunction_CAST (self );
749
760
if (value == Py_None )
750
761
value = NULL ;
751
762
/* Legal to del f.func_kwdefaults.
@@ -771,54 +782,6 @@ func_set_kwdefaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignor
771
782
return 0 ;
772
783
}
773
784
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
- }
822
785
823
786
/*[clinic input]
824
787
@critical_section
@@ -833,8 +796,7 @@ function___annotations___get_impl(PyFunctionObject *self)
833
796
/*[clinic end generated code: output=a4cf4c884c934cbb input=92643d7186c1ad0c]*/
834
797
{
835
798
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 ) {
838
800
self -> func_annotations = PyDict_New ();
839
801
if (self -> func_annotations == NULL )
840
802
return NULL ;
@@ -864,7 +826,6 @@ function___annotations___set_impl(PyFunctionObject *self, PyObject *value)
864
826
return -1 ;
865
827
}
866
828
Py_XSETREF (self -> func_annotations , Py_XNewRef (value ));
867
- Py_CLEAR (self -> func_annotate );
868
829
return 0 ;
869
830
}
870
831
@@ -925,7 +886,6 @@ static PyGetSetDef func_getsetlist[] = {
925
886
{"__defaults__" , func_get_defaults , func_set_defaults },
926
887
{"__kwdefaults__" , func_get_kwdefaults , func_set_kwdefaults },
927
888
FUNCTION___ANNOTATIONS___GETSETDEF
928
- FUNCTION___ANNOTATE___GETSETDEF
929
889
{"__dict__" , PyObject_GenericGetDict , PyObject_GenericSetDict },
930
890
{"__name__" , func_get_name , func_set_name },
931
891
{"__qualname__" , func_get_qualname , func_set_qualname },
0 commit comments