LCOV - code coverage report
Current view: top level - Python/clinic - _warnings.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 2 85 2.4 %
Date: 2023-03-20 08:15:36 Functions: 1 3 33.3 %
Branches: 0 70 0.0 %

           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                 :            : PyDoc_STRVAR(warnings_warn__doc__,
      12                 :            : "warn($module, /, message, category=None, stacklevel=1, source=None, *,\n"
      13                 :            : "     skip_file_prefixes=<unrepresentable>)\n"
      14                 :            : "--\n"
      15                 :            : "\n"
      16                 :            : "Issue a warning, or maybe ignore it or raise an exception.\n"
      17                 :            : "\n"
      18                 :            : "  message\n"
      19                 :            : "    Text of the warning message.\n"
      20                 :            : "  category\n"
      21                 :            : "    The Warning category subclass. Defaults to UserWarning.\n"
      22                 :            : "  stacklevel\n"
      23                 :            : "    How far up the call stack to make this warning appear. A value of 2 for\n"
      24                 :            : "    example attributes the warning to the caller of the code calling warn().\n"
      25                 :            : "  source\n"
      26                 :            : "    If supplied, the destroyed object which emitted a ResourceWarning\n"
      27                 :            : "  skip_file_prefixes\n"
      28                 :            : "    An optional tuple of module filename prefixes indicating frames to skip\n"
      29                 :            : "    during stacklevel computations for stack frame attribution.");
      30                 :            : 
      31                 :            : #define WARNINGS_WARN_METHODDEF    \
      32                 :            :     {"warn", _PyCFunction_CAST(warnings_warn), METH_FASTCALL|METH_KEYWORDS, warnings_warn__doc__},
      33                 :            : 
      34                 :            : static PyObject *
      35                 :            : warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
      36                 :            :                    Py_ssize_t stacklevel, PyObject *source,
      37                 :            :                    PyTupleObject *skip_file_prefixes);
      38                 :            : 
      39                 :            : static PyObject *
      40                 :          0 : warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      41                 :            : {
      42                 :          0 :     PyObject *return_value = NULL;
      43                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      44                 :            : 
      45                 :            :     #define NUM_KEYWORDS 5
      46                 :            :     static struct {
      47                 :            :         PyGC_Head _this_is_not_used;
      48                 :            :         PyObject_VAR_HEAD
      49                 :            :         PyObject *ob_item[NUM_KEYWORDS];
      50                 :            :     } _kwtuple = {
      51                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
      52                 :            :         .ob_item = { &_Py_ID(message), &_Py_ID(category), &_Py_ID(stacklevel), &_Py_ID(source), &_Py_ID(skip_file_prefixes), },
      53                 :            :     };
      54                 :            :     #undef NUM_KEYWORDS
      55                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
      56                 :            : 
      57                 :            :     #else  // !Py_BUILD_CORE
      58                 :            :     #  define KWTUPLE NULL
      59                 :            :     #endif  // !Py_BUILD_CORE
      60                 :            : 
      61                 :            :     static const char * const _keywords[] = {"message", "category", "stacklevel", "source", "skip_file_prefixes", NULL};
      62                 :            :     static _PyArg_Parser _parser = {
      63                 :            :         .keywords = _keywords,
      64                 :            :         .fname = "warn",
      65                 :            :         .kwtuple = KWTUPLE,
      66                 :            :     };
      67                 :            :     #undef KWTUPLE
      68                 :            :     PyObject *argsbuf[5];
      69         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
      70                 :            :     PyObject *message;
      71                 :          0 :     PyObject *category = Py_None;
      72                 :          0 :     Py_ssize_t stacklevel = 1;
      73                 :          0 :     PyObject *source = Py_None;
      74                 :          0 :     PyTupleObject *skip_file_prefixes = NULL;
      75                 :            : 
      76   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
             #  #  #  # ]
      77         [ #  # ]:          0 :     if (!args) {
      78                 :          0 :         goto exit;
      79                 :            :     }
      80                 :          0 :     message = args[0];
      81         [ #  # ]:          0 :     if (!noptargs) {
      82                 :          0 :         goto skip_optional_pos;
      83                 :            :     }
      84         [ #  # ]:          0 :     if (args[1]) {
      85                 :          0 :         category = args[1];
      86         [ #  # ]:          0 :         if (!--noptargs) {
      87                 :          0 :             goto skip_optional_pos;
      88                 :            :         }
      89                 :            :     }
      90         [ #  # ]:          0 :     if (args[2]) {
      91                 :            :         {
      92                 :          0 :             Py_ssize_t ival = -1;
      93                 :          0 :             PyObject *iobj = _PyNumber_Index(args[2]);
      94         [ #  # ]:          0 :             if (iobj != NULL) {
      95                 :          0 :                 ival = PyLong_AsSsize_t(iobj);
      96                 :          0 :                 Py_DECREF(iobj);
      97                 :            :             }
      98   [ #  #  #  # ]:          0 :             if (ival == -1 && PyErr_Occurred()) {
      99                 :          0 :                 goto exit;
     100                 :            :             }
     101                 :          0 :             stacklevel = ival;
     102                 :            :         }
     103         [ #  # ]:          0 :         if (!--noptargs) {
     104                 :          0 :             goto skip_optional_pos;
     105                 :            :         }
     106                 :            :     }
     107         [ #  # ]:          0 :     if (args[3]) {
     108                 :          0 :         source = args[3];
     109         [ #  # ]:          0 :         if (!--noptargs) {
     110                 :          0 :             goto skip_optional_pos;
     111                 :            :         }
     112                 :            :     }
     113                 :          0 : skip_optional_pos:
     114         [ #  # ]:          0 :     if (!noptargs) {
     115                 :          0 :         goto skip_optional_kwonly;
     116                 :            :     }
     117         [ #  # ]:          0 :     if (!PyTuple_Check(args[4])) {
     118                 :          0 :         _PyArg_BadArgument("warn", "argument 'skip_file_prefixes'", "tuple", args[4]);
     119                 :          0 :         goto exit;
     120                 :            :     }
     121                 :          0 :     skip_file_prefixes = (PyTupleObject *)args[4];
     122                 :          0 : skip_optional_kwonly:
     123                 :          0 :     return_value = warnings_warn_impl(module, message, category, stacklevel, source, skip_file_prefixes);
     124                 :            : 
     125                 :          0 : exit:
     126                 :          0 :     return return_value;
     127                 :            : }
     128                 :            : 
     129                 :            : PyDoc_STRVAR(warnings_warn_explicit__doc__,
     130                 :            : "warn_explicit($module, /, message, category, filename, lineno,\n"
     131                 :            : "              module=<unrepresentable>, registry=None,\n"
     132                 :            : "              module_globals=None, source=None)\n"
     133                 :            : "--\n"
     134                 :            : "\n"
     135                 :            : "Issue a warning, or maybe ignore it or raise an exception.");
     136                 :            : 
     137                 :            : #define WARNINGS_WARN_EXPLICIT_METHODDEF    \
     138                 :            :     {"warn_explicit", _PyCFunction_CAST(warnings_warn_explicit), METH_FASTCALL|METH_KEYWORDS, warnings_warn_explicit__doc__},
     139                 :            : 
     140                 :            : static PyObject *
     141                 :            : warnings_warn_explicit_impl(PyObject *module, PyObject *message,
     142                 :            :                             PyObject *category, PyObject *filename,
     143                 :            :                             int lineno, PyObject *mod, PyObject *registry,
     144                 :            :                             PyObject *module_globals, PyObject *sourceobj);
     145                 :            : 
     146                 :            : static PyObject *
     147                 :          0 : warnings_warn_explicit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     148                 :            : {
     149                 :          0 :     PyObject *return_value = NULL;
     150                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     151                 :            : 
     152                 :            :     #define NUM_KEYWORDS 8
     153                 :            :     static struct {
     154                 :            :         PyGC_Head _this_is_not_used;
     155                 :            :         PyObject_VAR_HEAD
     156                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     157                 :            :     } _kwtuple = {
     158                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     159                 :            :         .ob_item = { &_Py_ID(message), &_Py_ID(category), &_Py_ID(filename), &_Py_ID(lineno), &_Py_ID(module), &_Py_ID(registry), &_Py_ID(module_globals), &_Py_ID(source), },
     160                 :            :     };
     161                 :            :     #undef NUM_KEYWORDS
     162                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     163                 :            : 
     164                 :            :     #else  // !Py_BUILD_CORE
     165                 :            :     #  define KWTUPLE NULL
     166                 :            :     #endif  // !Py_BUILD_CORE
     167                 :            : 
     168                 :            :     static const char * const _keywords[] = {"message", "category", "filename", "lineno", "module", "registry", "module_globals", "source", NULL};
     169                 :            :     static _PyArg_Parser _parser = {
     170                 :            :         .keywords = _keywords,
     171                 :            :         .fname = "warn_explicit",
     172                 :            :         .kwtuple = KWTUPLE,
     173                 :            :     };
     174                 :            :     #undef KWTUPLE
     175                 :            :     PyObject *argsbuf[8];
     176         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
     177                 :            :     PyObject *message;
     178                 :            :     PyObject *category;
     179                 :            :     PyObject *filename;
     180                 :            :     int lineno;
     181                 :          0 :     PyObject *mod = NULL;
     182                 :          0 :     PyObject *registry = Py_None;
     183                 :          0 :     PyObject *module_globals = Py_None;
     184                 :          0 :     PyObject *sourceobj = Py_None;
     185                 :            : 
     186   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 8, 0, argsbuf);
             #  #  #  # ]
     187         [ #  # ]:          0 :     if (!args) {
     188                 :          0 :         goto exit;
     189                 :            :     }
     190                 :          0 :     message = args[0];
     191                 :          0 :     category = args[1];
     192         [ #  # ]:          0 :     if (!PyUnicode_Check(args[2])) {
     193                 :          0 :         _PyArg_BadArgument("warn_explicit", "argument 'filename'", "str", args[2]);
     194                 :          0 :         goto exit;
     195                 :            :     }
     196         [ #  # ]:          0 :     if (PyUnicode_READY(args[2]) == -1) {
     197                 :          0 :         goto exit;
     198                 :            :     }
     199                 :          0 :     filename = args[2];
     200                 :          0 :     lineno = _PyLong_AsInt(args[3]);
     201   [ #  #  #  # ]:          0 :     if (lineno == -1 && PyErr_Occurred()) {
     202                 :          0 :         goto exit;
     203                 :            :     }
     204         [ #  # ]:          0 :     if (!noptargs) {
     205                 :          0 :         goto skip_optional_pos;
     206                 :            :     }
     207         [ #  # ]:          0 :     if (args[4]) {
     208                 :          0 :         mod = args[4];
     209         [ #  # ]:          0 :         if (!--noptargs) {
     210                 :          0 :             goto skip_optional_pos;
     211                 :            :         }
     212                 :            :     }
     213         [ #  # ]:          0 :     if (args[5]) {
     214                 :          0 :         registry = args[5];
     215         [ #  # ]:          0 :         if (!--noptargs) {
     216                 :          0 :             goto skip_optional_pos;
     217                 :            :         }
     218                 :            :     }
     219         [ #  # ]:          0 :     if (args[6]) {
     220                 :          0 :         module_globals = args[6];
     221         [ #  # ]:          0 :         if (!--noptargs) {
     222                 :          0 :             goto skip_optional_pos;
     223                 :            :         }
     224                 :            :     }
     225                 :          0 :     sourceobj = args[7];
     226                 :          0 : skip_optional_pos:
     227                 :          0 :     return_value = warnings_warn_explicit_impl(module, message, category, filename, lineno, mod, registry, module_globals, sourceobj);
     228                 :            : 
     229                 :          0 : exit:
     230                 :          0 :     return return_value;
     231                 :            : }
     232                 :            : 
     233                 :            : PyDoc_STRVAR(warnings_filters_mutated__doc__,
     234                 :            : "_filters_mutated($module, /)\n"
     235                 :            : "--\n"
     236                 :            : "\n");
     237                 :            : 
     238                 :            : #define WARNINGS_FILTERS_MUTATED_METHODDEF    \
     239                 :            :     {"_filters_mutated", (PyCFunction)warnings_filters_mutated, METH_NOARGS, warnings_filters_mutated__doc__},
     240                 :            : 
     241                 :            : static PyObject *
     242                 :            : warnings_filters_mutated_impl(PyObject *module);
     243                 :            : 
     244                 :            : static PyObject *
     245                 :        330 : warnings_filters_mutated(PyObject *module, PyObject *Py_UNUSED(ignored))
     246                 :            : {
     247                 :        330 :     return warnings_filters_mutated_impl(module);
     248                 :            : }
     249                 :            : /*[clinic end generated code: output=20429719d7223bdc input=a9049054013a1b77]*/

Generated by: LCOV version 1.14