Coverage Report

Created: 2026-10-31 06:21

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