Skip to content

Commit 878eb69

Browse files
authored
t-strings: cosmetics (python#66)
1 parent f09d99f commit 878eb69

File tree

13 files changed

+22
-35
lines changed

13 files changed

+22
-35
lines changed

Include/internal/pycore_template.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ extern "C" {
99
# error "this header requires Py_BUILD_CORE define"
1010
#endif
1111

12-
#include "pycore_stackref.h" // _PyStackRef
13-
1412
extern PyTypeObject _PyTemplate_Type;
1513
extern PyTypeObject _PyTemplateIter_Type;
1614

Lib/string/templatelib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Support for template string literals (t-strings)."""
22

3-
from _templatelib import Template, Interpolation
3+
from _templatelib import Interpolation, Template

Lib/test/test_tstring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from string.templatelib import Template, Interpolation
55

66

7-
def convert(value, conversion) -> object:
7+
def convert(value, conversion):
88
if conversion == "a":
99
return ascii(value)
1010
elif conversion == "r":
@@ -14,7 +14,7 @@ def convert(value, conversion) -> object:
1414
return value
1515

1616

17-
def f(template) -> str:
17+
def f(template):
1818
parts = []
1919
for item in template:
2020
match item:

Modules/_templatelibmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* interpreter-internal types for string.templatelib */
22

33
#include "Python.h"
4-
#include "pycore_template.h" // _PyTemplate_Type
54
#include "pycore_interpolation.h" // _PyInterpolation_Type
5+
#include "pycore_template.h" // _PyTemplate_Type
66

77
static int
88
_templatelib_exec(PyObject *m)
@@ -26,7 +26,7 @@ static struct PyModuleDef_Slot _templatelib_slots[] = {
2626
static struct PyModuleDef _templatemodule = {
2727
.m_base = PyModuleDef_HEAD_INIT,
2828
.m_name = "_templatelib",
29-
.m_doc = "Interpreter-internal types for t-string templates.",
29+
.m_doc = "Interpreter types for template string literals (t-strings).",
3030
.m_size = 0,
3131
.m_slots = _templatelib_slots,
3232
};

Objects/interpolationobject.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* t-string Interpolation object implementation */
2-
#include "Python.h"
3-
#include <stddef.h>
42

3+
#include "Python.h"
54
#include "pycore_initconfig.h" // _PyStatus_OK
6-
#include "pycore_stackref.h" // _PyStackRef
7-
#include "pycore_global_objects.h" // _Py_STR
8-
#include "pycore_runtime.h" // _Py_STR
9-
105
#include "pycore_interpolation.h"
116

127
static int

Objects/object.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "pycore_initconfig.h" // _PyStatus_OK()
1717
#include "pycore_instruction_sequence.h" // _PyInstructionSequence_Type
1818
#include "pycore_interpolation.h" // _PyInterpolation_Type
19-
#include "pycore_hashtable.h" // _Py_hashtable_new()
2019
#include "pycore_list.h" // _PyList_DebugMallocStats()
2120
#include "pycore_long.h" // _PyLong_GetZero()
2221
#include "pycore_memoryobject.h" // _PyManagedBuffer_Type
@@ -27,7 +26,7 @@
2726
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
2827
#include "pycore_pystate.h" // _PyThreadState_GET()
2928
#include "pycore_symtable.h" // PySTEntry_Type
30-
#include "pycore_template.h" // _PyTemplate_Type
29+
#include "pycore_template.h" // _PyTemplate_Type _PyTemplateIter_Type
3130
#include "pycore_tuple.h" // _PyTuple_DebugMallocStats()
3231
#include "pycore_typeobject.h" // _PyBufferWrapper_Type
3332
#include "pycore_typevarobject.h" // _PyTypeAlias_Type
@@ -2412,6 +2411,7 @@ static PyTypeObject* static_types[] = {
24122411
&_PyHamt_CollisionNode_Type,
24132412
&_PyHamt_Type,
24142413
&_PyInstructionSequence_Type,
2414+
&_PyInterpolation_Type,
24152415
&_PyLegacyEventHandler_Type,
24162416
&_PyLineIterator,
24172417
&_PyManagedBuffer_Type,
@@ -2421,6 +2421,8 @@ static PyTypeObject* static_types[] = {
24212421
&_PyNone_Type,
24222422
&_PyNotImplemented_Type,
24232423
&_PyPositionsIterator,
2424+
&_PyTemplate_Type,
2425+
&_PyTemplateIter_Type,
24242426
&_PyUnicodeASCIIIter_Type,
24252427
&_PyUnion_Type,
24262428
#ifdef _Py_TIER2
@@ -2431,9 +2433,6 @@ static PyTypeObject* static_types[] = {
24312433
&_PyWeakref_RefType,
24322434
&_PyTypeAlias_Type,
24332435
&_PyNoDefault_Type,
2434-
&_PyInterpolation_Type,
2435-
&_PyTemplate_Type,
2436-
&_PyTemplateIter_Type,
24372436

24382437
// subclasses: _PyTypes_FiniTypes() deallocates them before their base
24392438
// class

Objects/templateobject.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
/* t-string Template object implementation */
2-
#include "Python.h"
3-
#include <stddef.h>
4-
5-
#include "pycore_stackref.h" // _PyStackRef
6-
#include "pycore_global_objects.h" // _Py_STR
7-
#include "pycore_runtime.h" // _Py_STR
82

3+
#include "Python.h"
4+
#include "pycore_interpolation.h" // _PyInterpolation_Check()
95
#include "pycore_template.h"
10-
#include "pycore_interpolation.h"
116

127
typedef struct {
138
PyObject_HEAD

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5656
#include "pycore_pyhash.h" // _Py_HashSecret_t
5757
#include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding()
5858
#include "pycore_pystate.h" // _PyInterpreterState_GET()
59+
#include "pycore_template.h" // _PyTemplate_Type
5960
#include "pycore_tuple.h" // _PyTuple_FromArray()
6061
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
6162
#include "pycore_unicodeobject.h" // struct _Py_unicode_state
6263
#include "pycore_unicodeobject_generated.h" // _PyUnicode_InitStaticStrings()
63-
#include "pycore_template.h" // _PyTemplate_Type
6464

6565
#include "stringlib/eq.h" // unicode_eq()
6666
#include <stddef.h> // ptrdiff_t

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
1717
#include "pycore_function.h"
1818
#include "pycore_instruments.h"
19+
#include "pycore_interpolation.h" // _PyInterpolation_FromStackRefStealOnSuccess()
1920
#include "pycore_intrinsics.h"
2021
#include "pycore_long.h" // _PyLong_GetZero()
2122
#include "pycore_moduleobject.h" // PyModuleObject
@@ -30,10 +31,9 @@
3031
#include "pycore_setobject.h" // _PySet_NextEntry()
3132
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
3233
#include "pycore_stackref.h"
34+
#include "pycore_template.h" // _PyTemplate_From{List,Values}()
3335
#include "pycore_tuple.h" // _PyTuple_ITEMS()
3436
#include "pycore_typeobject.h" // _PySuper_Lookup()
35-
#include "pycore_interpolation.h"
36-
#include "pycore_template.h"
3737

3838
#include "pycore_dict.h"
3939
#include "dictobject.h"

Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "pycore_import.h" // _PyImport_IsDefaultImportFunc()
2020
#include "pycore_instruments.h"
2121
#include "pycore_interpframe.h" // _PyFrame_SetStackPointer()
22+
#include "pycore_interpolation.h" // _PyInterpolation_FromStackRefStealOnSuccess()
2223
#include "pycore_intrinsics.h"
2324
#include "pycore_jit.h"
2425
#include "pycore_list.h" // _PyList_GetItemRef()
@@ -36,6 +37,7 @@
3637
#include "pycore_setobject.h" // _PySet_Update()
3738
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
3839
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString()
40+
#include "pycore_template.h" // _PyTemplate_From{List,Values}()
3941
#include "pycore_traceback.h" // _PyTraceBack_FromFrame
4042
#include "pycore_tuple.h" // _PyTuple_ITEMS()
4143
#include "pycore_uop_ids.h" // Uops
@@ -46,8 +48,6 @@
4648
#include "pydtrace.h"
4749
#include "setobject.h"
4850
#include "pycore_stackref.h"
49-
#include "pycore_template.h"
50-
#include "pycore_interpolation.h"
5151

5252
#include <stdbool.h> // bool
5353

Python/jit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "pycore_frame.h"
1313
#include "pycore_function.h"
1414
#include "pycore_interpframe.h"
15+
#include "pycore_interpolation.h"
1516
#include "pycore_intrinsics.h"
1617
#include "pycore_list.h"
1718
#include "pycore_long.h"
@@ -21,10 +22,9 @@
2122
#include "pycore_pyerrors.h"
2223
#include "pycore_setobject.h"
2324
#include "pycore_sliceobject.h"
25+
#include "pycore_template.h"
2426
#include "pycore_tuple.h"
2527
#include "pycore_unicodeobject.h"
26-
#include "pycore_interpolation.h"
27-
#include "pycore_template.h"
2828

2929
#include "pycore_jit.h"
3030

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "pycore_freelist.h" // _PyObject_ClearFreeLists()
1414
#include "pycore_global_objects_fini_generated.h" // _PyStaticObjects_CheckRefcnt()
1515
#include "pycore_initconfig.h" // _PyStatus_OK()
16+
#include "pycore_interpolation.h" // _PyInterpolation_InitTypes()
1617
#include "pycore_long.h" // _PyLong_InitTypes()
1718
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
1819
#include "pycore_obmalloc.h" // _PyMem_init_obmalloc()
@@ -33,7 +34,6 @@
3334
#include "pycore_uniqueid.h" // _PyObject_FinalizeUniqueIdPool()
3435
#include "pycore_warnings.h" // _PyWarnings_InitState()
3536
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
36-
#include "pycore_interpolation.h" // _PyInterpolation_InitTypes()
3737

3838
#include "opcode.h"
3939

Tools/jit/template.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "pycore_function.h"
1414
#include "pycore_genobject.h"
1515
#include "pycore_interpframe.h"
16+
#include "pycore_interpolation.h"
1617
#include "pycore_intrinsics.h"
1718
#include "pycore_jit.h"
1819
#include "pycore_list.h"
@@ -25,10 +26,9 @@
2526
#include "pycore_setobject.h"
2627
#include "pycore_sliceobject.h"
2728
#include "pycore_stackref.h"
29+
#include "pycore_template.h"
2830
#include "pycore_tuple.h"
2931
#include "pycore_unicodeobject.h"
30-
#include "pycore_interpolation.h"
31-
#include "pycore_template.h"
3232

3333
#include "ceval_macros.h"
3434

0 commit comments

Comments
 (0)