LCOV - code coverage report
Current view: top level - Objects/clinic - descrobject.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 36 40 90.0 %
Date: 2023-03-20 08:15:36 Functions: 2 2 100.0 %
Branches: 24 36 66.7 %

           Branch data     Line data    Source code
       1                 :            : /*[clinic input]
       2                 :            : preserve
       3                 :            : [clinic start generated code]*/
       4                 :            : 
       5                 :            : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6                 :            : #  include "pycore_gc.h"            // PyGC_Head
       7                 :            : #  include "pycore_runtime.h"       // _Py_ID()
       8                 :            : #endif
       9                 :            : 
      10                 :            : 
      11                 :            : static PyObject *
      12                 :            : mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
      13                 :            : 
      14                 :            : static PyObject *
      15                 :         38 : mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      16                 :            : {
      17                 :         38 :     PyObject *return_value = NULL;
      18                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      19                 :            : 
      20                 :            :     #define NUM_KEYWORDS 1
      21                 :            :     static struct {
      22                 :            :         PyGC_Head _this_is_not_used;
      23                 :            :         PyObject_VAR_HEAD
      24                 :            :         PyObject *ob_item[NUM_KEYWORDS];
      25                 :            :     } _kwtuple = {
      26                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
      27                 :            :         .ob_item = { &_Py_ID(mapping), },
      28                 :            :     };
      29                 :            :     #undef NUM_KEYWORDS
      30                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
      31                 :            : 
      32                 :            :     #else  // !Py_BUILD_CORE
      33                 :            :     #  define KWTUPLE NULL
      34                 :            :     #endif  // !Py_BUILD_CORE
      35                 :            : 
      36                 :            :     static const char * const _keywords[] = {"mapping", NULL};
      37                 :            :     static _PyArg_Parser _parser = {
      38                 :            :         .keywords = _keywords,
      39                 :            :         .fname = "mappingproxy",
      40                 :            :         .kwtuple = KWTUPLE,
      41                 :            :     };
      42                 :            :     #undef KWTUPLE
      43                 :            :     PyObject *argsbuf[1];
      44                 :            :     PyObject * const *fastargs;
      45                 :         38 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
      46                 :            :     PyObject *mapping;
      47                 :            : 
      48   [ +  -  +  -  :         38 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
             +  -  +  - ]
      49         [ -  + ]:         38 :     if (!fastargs) {
      50                 :          0 :         goto exit;
      51                 :            :     }
      52                 :         38 :     mapping = fastargs[0];
      53                 :         38 :     return_value = mappingproxy_new_impl(type, mapping);
      54                 :            : 
      55                 :         38 : exit:
      56                 :         38 :     return return_value;
      57                 :            : }
      58                 :            : 
      59                 :            : PyDoc_STRVAR(property_init__doc__,
      60                 :            : "property(fget=None, fset=None, fdel=None, doc=None)\n"
      61                 :            : "--\n"
      62                 :            : "\n"
      63                 :            : "Property attribute.\n"
      64                 :            : "\n"
      65                 :            : "  fget\n"
      66                 :            : "    function to be used for getting an attribute value\n"
      67                 :            : "  fset\n"
      68                 :            : "    function to be used for setting an attribute value\n"
      69                 :            : "  fdel\n"
      70                 :            : "    function to be used for del\'ing an attribute\n"
      71                 :            : "  doc\n"
      72                 :            : "    docstring\n"
      73                 :            : "\n"
      74                 :            : "Typical use is to define a managed attribute x:\n"
      75                 :            : "\n"
      76                 :            : "class C(object):\n"
      77                 :            : "    def getx(self): return self._x\n"
      78                 :            : "    def setx(self, value): self._x = value\n"
      79                 :            : "    def delx(self): del self._x\n"
      80                 :            : "    x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n"
      81                 :            : "\n"
      82                 :            : "Decorators make defining new properties or modifying existing ones easy:\n"
      83                 :            : "\n"
      84                 :            : "class C(object):\n"
      85                 :            : "    @property\n"
      86                 :            : "    def x(self):\n"
      87                 :            : "        \"I am the \'x\' property.\"\n"
      88                 :            : "        return self._x\n"
      89                 :            : "    @x.setter\n"
      90                 :            : "    def x(self, value):\n"
      91                 :            : "        self._x = value\n"
      92                 :            : "    @x.deleter\n"
      93                 :            : "    def x(self):\n"
      94                 :            : "        del self._x");
      95                 :            : 
      96                 :            : static int
      97                 :            : property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
      98                 :            :                    PyObject *fdel, PyObject *doc);
      99                 :            : 
     100                 :            : static int
     101                 :        438 : property_init(PyObject *self, PyObject *args, PyObject *kwargs)
     102                 :            : {
     103                 :        438 :     int return_value = -1;
     104                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     105                 :            : 
     106                 :            :     #define NUM_KEYWORDS 4
     107                 :            :     static struct {
     108                 :            :         PyGC_Head _this_is_not_used;
     109                 :            :         PyObject_VAR_HEAD
     110                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     111                 :            :     } _kwtuple = {
     112                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     113                 :            :         .ob_item = { &_Py_ID(fget), &_Py_ID(fset), &_Py_ID(fdel), &_Py_ID(doc), },
     114                 :            :     };
     115                 :            :     #undef NUM_KEYWORDS
     116                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     117                 :            : 
     118                 :            :     #else  // !Py_BUILD_CORE
     119                 :            :     #  define KWTUPLE NULL
     120                 :            :     #endif  // !Py_BUILD_CORE
     121                 :            : 
     122                 :            :     static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL};
     123                 :            :     static _PyArg_Parser _parser = {
     124                 :            :         .keywords = _keywords,
     125                 :            :         .fname = "property",
     126                 :            :         .kwtuple = KWTUPLE,
     127                 :            :     };
     128                 :            :     #undef KWTUPLE
     129                 :            :     PyObject *argsbuf[4];
     130                 :            :     PyObject * const *fastargs;
     131                 :        438 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     132         [ +  + ]:        438 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
     133                 :        438 :     PyObject *fget = NULL;
     134                 :        438 :     PyObject *fset = NULL;
     135                 :        438 :     PyObject *fdel = NULL;
     136                 :        438 :     PyObject *doc = NULL;
     137                 :            : 
     138   [ +  +  +  -  :        438 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 4, 0, argsbuf);
             +  -  +  - ]
     139         [ -  + ]:        438 :     if (!fastargs) {
     140                 :          0 :         goto exit;
     141                 :            :     }
     142         [ -  + ]:        438 :     if (!noptargs) {
     143                 :          0 :         goto skip_optional_pos;
     144                 :            :     }
     145         [ +  - ]:        438 :     if (fastargs[0]) {
     146                 :        438 :         fget = fastargs[0];
     147         [ +  + ]:        438 :         if (!--noptargs) {
     148                 :        345 :             goto skip_optional_pos;
     149                 :            :         }
     150                 :            :     }
     151         [ +  + ]:         93 :     if (fastargs[1]) {
     152                 :         91 :         fset = fastargs[1];
     153         [ +  + ]:         91 :         if (!--noptargs) {
     154                 :         13 :             goto skip_optional_pos;
     155                 :            :         }
     156                 :            :     }
     157         [ +  + ]:         80 :     if (fastargs[2]) {
     158                 :         78 :         fdel = fastargs[2];
     159         [ -  + ]:         78 :         if (!--noptargs) {
     160                 :          0 :             goto skip_optional_pos;
     161                 :            :         }
     162                 :            :     }
     163                 :         80 :     doc = fastargs[3];
     164                 :        438 : skip_optional_pos:
     165                 :        438 :     return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc);
     166                 :            : 
     167                 :        438 : exit:
     168                 :        438 :     return return_value;
     169                 :            : }
     170                 :            : /*[clinic end generated code: output=8dc1ddfcf764ac8e input=a9049054013a1b77]*/

Generated by: LCOV version 1.14