Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Python/clinic/Python-tokenize.c.h
Line
Count
Source
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
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
10
#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL()
11
12
static PyObject *
13
tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
14
                       int extra_tokens, const char *encoding);
15
16
static PyObject *
17
tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
18
20
{
19
20
    PyObject *return_value = NULL;
20
20
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
21
22
20
    #define NUM_KEYWORDS 2
23
20
    static struct {
24
20
        PyGC_Head _this_is_not_used;
25
20
        PyObject_VAR_HEAD
26
20
        Py_hash_t ob_hash;
27
20
        PyObject *ob_item[NUM_KEYWORDS];
28
20
    } _kwtuple = {
29
20
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
30
20
        .ob_hash = -1,
31
20
        .ob_item = { &_Py_ID(extra_tokens), &_Py_ID(encoding), },
32
20
    };
33
20
    #undef NUM_KEYWORDS
34
20
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
35
36
    #else  // !Py_BUILD_CORE
37
    #  define KWTUPLE NULL
38
    #endif  // !Py_BUILD_CORE
39
40
20
    static const char * const _keywords[] = {"", "extra_tokens", "encoding", NULL};
41
20
    static _PyArg_Parser _parser = {
42
20
        .keywords = _keywords,
43
20
        .fname = "tokenizeriter",
44
20
        .kwtuple = KWTUPLE,
45
20
    };
46
20
    #undef KWTUPLE
47
20
    PyObject *argsbuf[3];
48
20
    PyObject * const *fastargs;
49
20
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
50
20
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
51
20
    PyObject *readline;
52
20
    int extra_tokens;
53
20
    const char *encoding = NULL;
54
55
20
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
56
20
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 1, /*varpos*/ 0, argsbuf);
57
20
    if (!fastargs) {
58
0
        goto exit;
59
0
    }
60
20
    readline = fastargs[0];
61
20
    extra_tokens = PyObject_IsTrue(fastargs[1]);
62
20
    if (extra_tokens < 0) {
63
0
        goto exit;
64
0
    }
65
20
    if (!noptargs) {
66
16
        goto skip_optional_kwonly;
67
16
    }
68
4
    if (!PyUnicode_Check(fastargs[2])) {
69
0
        _PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]);
70
0
        goto exit;
71
0
    }
72
4
    encoding = _PyUnicode_AsUTF8NoNUL(fastargs[2]);
73
4
    if (encoding == NULL) {
74
0
        goto exit;
75
0
    }
76
20
skip_optional_kwonly:
77
20
    return_value = tokenizeriter_new_impl(type, readline, extra_tokens, encoding);
78
79
20
exit:
80
20
    return return_value;
81
20
}
82
/*[clinic end generated code: output=f9091945b96e09b7 input=a9049054013a1b77]*/