#9418: first step of moving private string methods to _string module. · pythoncapi/cpython@66c221e · GitHub
Skip to content

Commit 66c221e

Browse files
committed
python#9418: first step of moving private string methods to _string module.
1 parent 268e4d4 commit 66c221e

6 files changed

Lines changed: 47 additions & 8 deletions

File tree

Lib/string.py

Lines changed: 6 additions & 4 deletions

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9418: Moved private string methods ``_formatter_parser`` and
14+
``_formatter_field_name_split`` into a new ``_string`` module.
15+
1316
- Issue #9992: Remove PYTHONFSENCODING environment variable.
1417

1518
Library

Modules/config.c.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern PyObject* PyInit_imp(void);
2929
extern PyObject* PyInit_gc(void);
3030
extern PyObject* PyInit__ast(void);
3131
extern PyObject* _PyWarnings_Init(void);
32+
extern PyObject* PyInit__string(void);
3233

3334
struct _inittab _PyImport_Inittab[] = {
3435

@@ -54,6 +55,9 @@ struct _inittab _PyImport_Inittab[] = {
5455
/* This lives in _warnings.c */
5556
{"_warnings", _PyWarnings_Init},
5657

58+
/* This lives in Objects/unicodeobject.c */
59+
{"_string", PyInit__string},
60+
5761
/* Sentinel */
5862
{0, 0}
5963
};

Objects/stringlib/string_format.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ static PyTypeObject PyFormatterIter_Type = {
11801180
describing the parsed elements. It's a wrapper around
11811181
stringlib/string_format.h's MarkupIterator */
11821182
static PyObject *
1183-
formatter_parser(STRINGLIB_OBJECT *self)
1183+
formatter_parser(PyObject *ignored, STRINGLIB_OBJECT *self)
11841184
{
11851185
formatteriterobject *it;
11861186

@@ -1315,7 +1315,7 @@ static PyTypeObject PyFieldNameIter_Type = {
13151315
field_name_split. The iterator it returns is a
13161316
FieldNameIterator */
13171317
static PyObject *
1318-
formatter_field_name_split(STRINGLIB_OBJECT *self)
1318+
formatter_field_name_split(PyObject *ignored, STRINGLIB_OBJECT *self)
13191319
{
13201320
SubString first;
13211321
Py_ssize_t first_idx;

Objects/unicodeobject.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8968,8 +8968,6 @@ static PyMethodDef unicode_methods[] = {
89688968
{"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__},
89698969
{"format", (PyCFunction) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__},
89708970
{"__format__", (PyCFunction) unicode__format__, METH_VARARGS, p_format__doc__},
8971-
{"_formatter_field_name_split", (PyCFunction) formatter_field_name_split, METH_NOARGS},
8972-
{"_formatter_parser", (PyCFunction) formatter_parser, METH_NOARGS},
89738971
{"maketrans", (PyCFunction) unicode_maketrans,
89748972
METH_VARARGS | METH_STATIC, maketrans__doc__},
89758973
{"__sizeof__", (PyCFunction) unicode__sizeof__, METH_NOARGS, sizeof__doc__},
@@ -10170,6 +10168,36 @@ PyUnicode_AsUnicodeCopy(PyObject *object)
1017010168
return copy;
1017110169
}
1017210170

10171+
/* A _string module, to export formatter_parser and formatter_field_name_split
10172+
to the string.Formatter class implemented in Python. */
10173+
10174+
static PyMethodDef _string_methods[] = {
10175+
{"formatter_field_name_split", (PyCFunction) formatter_field_name_split,
10176+
METH_O, PyDoc_STR("split the argument as a field name")},
10177+
{"formatter_parser", (PyCFunction) formatter_parser,
10178+
METH_O, PyDoc_STR("parse the argument as a format string")},
10179+
{NULL, NULL}
10180+
};
10181+
10182+
static struct PyModuleDef _string_module = {
10183+
PyModuleDef_HEAD_INIT,
10184+
"_string",
10185+
PyDoc_STR("string helper module"),
10186+
0,
10187+
_string_methods,
10188+
NULL,
10189+
NULL,
10190+
NULL,
10191+
NULL
10192+
};
10193+
10194+
PyMODINIT_FUNC
10195+
PyInit__string(void)
10196+
{
10197+
return PyModule_Create(&_string_module);
10198+
}
10199+
10200+
1017310201
#ifdef __cplusplus
1017410202
}
1017510203
#endif

PC/config.c

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)