Skip to content

Commit 77822be

Browse files
authored
Make changes requested by Steering Council (python#57)
* Rename expr to expression, conv to conversion * Move templatelib under string lib * Add strings lib to LIBSUBDIRS * Update type of Template/TemplateIter/Interpolation
1 parent aad5d67 commit 77822be

10 files changed

+57
-54
lines changed

Include/internal/pycore_global_objects_fini_generated.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ struct _Py_global_strings {
356356
STRUCT_FOR_ID(consts)
357357
STRUCT_FOR_ID(context)
358358
STRUCT_FOR_ID(contravariant)
359-
STRUCT_FOR_ID(conv)
359+
STRUCT_FOR_ID(conversion)
360360
STRUCT_FOR_ID(cookie)
361361
STRUCT_FOR_ID(copy)
362362
STRUCT_FOR_ID(copyreg)
@@ -414,7 +414,7 @@ struct _Py_global_strings {
414414
STRUCT_FOR_ID(exception)
415415
STRUCT_FOR_ID(existing_file_name)
416416
STRUCT_FOR_ID(exp)
417-
STRUCT_FOR_ID(expr)
417+
STRUCT_FOR_ID(expression)
418418
STRUCT_FOR_ID(extend)
419419
STRUCT_FOR_ID(extra_tokens)
420420
STRUCT_FOR_ID(facility)

Include/internal/pycore_runtime_init_generated.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,7 @@ LIBSUBDIRS= asyncio \
24222422
re \
24232423
site-packages \
24242424
sqlite3 \
2425+
string \
24252426
sysconfig \
24262427
tkinter \
24272428
tomllib \

Objects/clinic/interpolationobject.c.h

+12-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/interpolationobject.c

+34-33
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,34 @@ class templatelib.Interpolation "interpolationobject *" "&_PyInterpolation_Type"
2222
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5b183514b4d7e5af]*/
2323

2424
int
25-
_conversion_converter(PyObject *arg, PyObject **conv)
25+
_conversion_converter(PyObject *arg, PyObject **conversion)
2626
{
2727
if (arg == Py_None) {
2828
return 1;
2929
}
3030

3131
if (!PyUnicode_Check(arg)) {
32-
_PyArg_BadArgument("Interpolation", "argument 'conv'", "str", arg);
32+
_PyArg_BadArgument("Interpolation", "argument 'conversion'", "str", arg);
3333
return 0;
3434
}
3535

3636
Py_ssize_t len;
3737
const char *conv_str = PyUnicode_AsUTF8AndSize(arg, &len);
3838
if (len != 1 || !(conv_str[0] == 'a' || conv_str[0] == 'r' || conv_str[0] == 's')) {
3939
PyErr_SetString(PyExc_ValueError,
40-
"Interpolation() argument 'conv' must be one of 's', 'a' or 'r'");
40+
"Interpolation() argument 'conversion' must be one of 's', 'a' or 'r'");
4141
return 0;
4242
}
4343

44-
*conv = arg;
44+
*conversion = arg;
4545
return 1;
4646
}
4747

4848
typedef struct {
4949
PyObject_HEAD
5050
PyObject *value;
51-
PyObject *expr;
52-
PyObject *conv;
51+
PyObject *expression;
52+
PyObject *conversion;
5353
PyObject *format_spec;
5454
} interpolationobject;
5555

@@ -58,24 +58,25 @@ typedef struct {
5858
templatelib.Interpolation.__new__ as interpolation_new
5959
6060
value: object
61-
expr: object(subclass_of='&PyUnicode_Type')
62-
conv: object(converter='_conversion_converter') = None
61+
expression: object(subclass_of='&PyUnicode_Type')
62+
conversion: object(converter='_conversion_converter') = None
6363
format_spec: object(subclass_of='&PyUnicode_Type', c_default='&_Py_STR(empty)') = ""
6464
[clinic start generated code]*/
6565

6666
static PyObject *
67-
interpolation_new_impl(PyTypeObject *type, PyObject *value, PyObject *expr,
68-
PyObject *conv, PyObject *format_spec)
69-
/*[clinic end generated code: output=417d59bccab99648 input=348d81ee06c4be20]*/
67+
interpolation_new_impl(PyTypeObject *type, PyObject *value,
68+
PyObject *expression, PyObject *conversion,
69+
PyObject *format_spec)
70+
/*[clinic end generated code: output=6488e288765bc1a9 input=0abc8e498fb744a7]*/
7071
{
7172
interpolationobject *self = (interpolationobject *) type->tp_alloc(type, 0);
7273
if (!self) {
7374
return NULL;
7475
}
7576

7677
Py_XSETREF(self->value, Py_NewRef(value));
77-
Py_XSETREF(self->expr, Py_NewRef(expr));
78-
Py_XSETREF(self->conv, Py_NewRef(conv));
78+
Py_XSETREF(self->expression, Py_NewRef(expression));
79+
Py_XSETREF(self->conversion, Py_NewRef(conversion));
7980
Py_XSETREF(self->format_spec, Py_NewRef(format_spec));
8081
return (PyObject *) self;
8182
}
@@ -84,8 +85,8 @@ static void
8485
interpolation_dealloc(interpolationobject *self)
8586
{
8687
Py_CLEAR(self->value);
87-
Py_CLEAR(self->expr);
88-
Py_CLEAR(self->conv);
88+
Py_CLEAR(self->expression);
89+
Py_CLEAR(self->conversion);
8990
Py_CLEAR(self->format_spec);
9091
Py_TYPE(self)->tp_free(self);
9192
}
@@ -95,8 +96,8 @@ interpolation_repr(interpolationobject *self)
9596
{
9697
return PyUnicode_FromFormat("%s(%R, %R, %R, %R)",
9798
_PyType_Name(Py_TYPE(self)),
98-
self->value, self->expr,
99-
self->conv, self->format_spec);
99+
self->value, self->expression,
100+
self->conversion, self->format_spec);
100101
}
101102

102103
static PyObject *
@@ -116,11 +117,11 @@ interpolation_compare(interpolationobject *self, PyObject *other, int op)
116117
if (valueeq == -1) {
117118
return NULL;
118119
}
119-
int expreq = PyUnicode_Compare(self->expr, other_i->expr);
120+
int expreq = PyUnicode_Compare(self->expression, other_i->expression);
120121
if (expreq == -1 && PyErr_Occurred()) {
121122
return NULL;
122123
}
123-
int conveq = PyObject_RichCompareBool(self->conv, other_i->conv, Py_EQ); // conv might be Py_None
124+
int conveq = PyObject_RichCompareBool(self->conversion, other_i->conversion, Py_EQ); // conversion might be Py_None
124125
if (conveq == -1) {
125126
return NULL;
126127
}
@@ -136,7 +137,7 @@ interpolation_compare(interpolationobject *self, PyObject *other, int op)
136137
static Py_hash_t
137138
interpolation_hash(interpolationobject *self)
138139
{
139-
PyObject *tuple = PyTuple_Pack(4, self->value, self->expr, self->conv, self->format_spec);
140+
PyObject *tuple = PyTuple_Pack(4, self->value, self->expression, self->conversion, self->format_spec);
140141
if (!tuple) {
141142
return -1;
142143
}
@@ -148,15 +149,15 @@ interpolation_hash(interpolationobject *self)
148149

149150
static PyMemberDef interpolation_members[] = {
150151
{"value", Py_T_OBJECT_EX, offsetof(interpolationobject, value), Py_READONLY, "Value"},
151-
{"expr", Py_T_OBJECT_EX, offsetof(interpolationobject, expr), Py_READONLY, "Expr"},
152-
{"conv", Py_T_OBJECT_EX, offsetof(interpolationobject, conv), Py_READONLY, "Conversion"},
152+
{"expression", Py_T_OBJECT_EX, offsetof(interpolationobject, expression), Py_READONLY, "Expression"},
153+
{"conversion", Py_T_OBJECT_EX, offsetof(interpolationobject, conversion), Py_READONLY, "Conversion"},
153154
{"format_spec", Py_T_OBJECT_EX, offsetof(interpolationobject, format_spec), Py_READONLY, "Format specifier"},
154155
{NULL}
155156
};
156157

157158
PyTypeObject _PyInterpolation_Type = {
158159
PyVarObject_HEAD_INIT(NULL, 0)
159-
.tp_name = "templatelib.Interpolation",
160+
.tp_name = "string.templatelib.Interpolation",
160161
.tp_doc = PyDoc_STR("Interpolation object"),
161162
.tp_basicsize = sizeof(interpolationobject),
162163
.tp_itemsize = 0,
@@ -172,32 +173,32 @@ PyTypeObject _PyInterpolation_Type = {
172173
static PyObject *
173174
_get_match_args(void)
174175
{
175-
PyObject *value = NULL, *expr = NULL, *conv = NULL, *format_spec = NULL;
176+
PyObject *value = NULL, *expression = NULL, *conversion = NULL, *format_spec = NULL;
176177
PyObject *tuple = NULL;
177178

178179
value = PyUnicode_FromString("value");
179180
if (!value) {
180181
goto error;
181182
}
182-
expr = PyUnicode_FromString("expr");
183-
if (!expr) {
183+
expression = PyUnicode_FromString("expression");
184+
if (!expression) {
184185
goto error;
185186
}
186-
conv = PyUnicode_FromString("conv");
187-
if (!conv) {
187+
conversion = PyUnicode_FromString("conversion");
188+
if (!conversion) {
188189
goto error;
189190
}
190191
format_spec = PyUnicode_FromString("format_spec");
191192
if (!format_spec) {
192193
goto error;
193194
}
194195

195-
tuple = PyTuple_Pack(4, value, expr, conv, format_spec);
196+
tuple = PyTuple_Pack(4, value, expression, conversion, format_spec);
196197

197198
error:
198199
Py_XDECREF(value);
199-
Py_XDECREF(expr);
200-
Py_XDECREF(conv);
200+
Py_XDECREF(expression);
201+
Py_XDECREF(conversion);
201202
Py_XDECREF(format_spec);
202203
return tuple;
203204

@@ -240,8 +241,8 @@ _PyInterpolation_FromStackRefSteal(_PyStackRef *values)
240241
PyTuple_SET_ITEM(args, 0, PyStackRef_AsPyObjectSteal(values[0]));
241242
PyTuple_SET_ITEM(args, 1, PyStackRef_AsPyObjectSteal(values[1]));
242243

243-
PyObject *conv = PyStackRef_AsPyObjectSteal(values[2]);
244-
PyTuple_SET_ITEM(args, 2, conv ? conv : Py_NewRef(Py_None));
244+
PyObject *conversion = PyStackRef_AsPyObjectSteal(values[2]);
245+
PyTuple_SET_ITEM(args, 2, conversion ? conversion : Py_NewRef(Py_None));
245246

246247
PyObject *format_spec = PyStackRef_AsPyObjectSteal(values[3]);
247248
PyTuple_SET_ITEM(args, 3, format_spec ? format_spec : &_Py_STR(empty));

Objects/templateobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ templateiter_dealloc(templateiterobject *self)
3939

4040
PyTypeObject _PyTemplateIter_Type = {
4141
PyVarObject_HEAD_INIT(NULL, 0)
42-
.tp_name = "templatelib.TemplateIter",
42+
.tp_name = "string.templatelib.TemplateIter",
4343
.tp_doc = PyDoc_STR("Template iterator object"),
4444
.tp_basicsize = sizeof(templateiterobject),
4545
.tp_itemsize = 0,
@@ -438,7 +438,7 @@ static PySequenceMethods template_as_sequence = {
438438

439439
PyTypeObject _PyTemplate_Type = {
440440
PyVarObject_HEAD_INIT(NULL, 0)
441-
.tp_name = "templatelib.Template",
441+
.tp_name = "string.templatelib.Template",
442442
.tp_doc = PyDoc_STR("Template object"),
443443
.tp_basicsize = sizeof(templateobject),
444444
.tp_itemsize = 0,

0 commit comments

Comments
 (0)