diff --git a/Lib/string/templatelib.py b/Lib/string/templatelib.py index 89199aebb9d09d..22f7edb68eb83a 100644 --- a/Lib/string/templatelib.py +++ b/Lib/string/templatelib.py @@ -1,3 +1,3 @@ -from _templatelib import Template, Interpolation +"""Support for template string literals (t-strings).""" -__all__ = ['Template', 'Interpolation'] +from _templatelib import Template, Interpolation diff --git a/Modules/Setup b/Modules/Setup index f75f44e98c7818..1d295669f48b0d 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -150,6 +150,7 @@ PYTHONPATH=$(COREPYTHONPATH) #_socket socketmodule.c #_statistics _statisticsmodule.c #_struct _struct.c +#_templatelib _templatelibmodule.c #_types _typesmodule.c #_typing _typingmodule.c #_zoneinfo _zoneinfo.c diff --git a/Modules/_templatelibmodule.c b/Modules/_templatelibmodule.c index 94c57c4443c4dc..54d06c85aba65d 100644 --- a/Modules/_templatelibmodule.c +++ b/Modules/_templatelibmodule.c @@ -1,12 +1,8 @@ -/* interpreter-internal types for templatelib */ - -#ifndef Py_BUILD_CORE -#define Py_BUILD_CORE -#endif +/* interpreter-internal types for string.templatelib */ #include "Python.h" -#include "pycore_template.h" -#include "pycore_interpolation.h" +#include "pycore_template.h" // _PyTemplate_Type +#include "pycore_interpolation.h" // _PyInterpolation_Type static int _templatelib_exec(PyObject *m) @@ -20,9 +16,6 @@ _templatelib_exec(PyObject *m) return 0; } -PyDoc_STRVAR(_templatelib_doc, -"Interpreter-internal types for t-string templates.\n"); - static struct PyModuleDef_Slot _templatelib_slots[] = { {Py_mod_exec, _templatelib_exec}, {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, @@ -31,15 +24,11 @@ static struct PyModuleDef_Slot _templatelib_slots[] = { }; static struct PyModuleDef _templatemodule = { - PyModuleDef_HEAD_INIT, - "_templatelib", - _templatelib_doc, - 0, - NULL, - _templatelib_slots, - NULL, - NULL, - NULL + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "_templatelib", + .m_doc = "Interpreter-internal types for t-string templates.", + .m_size = 0, + .m_slots = _templatelib_slots, }; PyMODINIT_FUNC diff --git a/Objects/interpolationobject.c b/Objects/interpolationobject.c index 57a857536a7ed0..ff0ffad0317ef2 100644 --- a/Objects/interpolationobject.c +++ b/Objects/interpolationobject.c @@ -1,4 +1,4 @@ -/* Interpolation object implementation */ +/* t-string Interpolation object implementation */ #include "Python.h" #include diff --git a/Objects/templateobject.c b/Objects/templateobject.c index ab517d55105082..b451fd2ad2900e 100644 --- a/Objects/templateobject.c +++ b/Objects/templateobject.c @@ -1,4 +1,4 @@ -/* Interpolation object implementation */ +/* t-string Template object implementation */ #include "Python.h" #include diff --git a/PC/config.c b/PC/config.c index 6ce2131c7b84d0..e09ad0db2ef5ee 100644 --- a/PC/config.c +++ b/PC/config.c @@ -19,6 +19,7 @@ extern PyObject* PyInit__operator(void); extern PyObject* PyInit__signal(void); extern PyObject* PyInit__statistics(void); extern PyObject* PyInit__sysconfig(void); +extern PyObject* PyInit__templatelib(void); extern PyObject* PyInit__types(void); extern PyObject* PyInit__typing(void); extern PyObject* PyInit_time(void); @@ -106,6 +107,7 @@ struct _inittab _PyImport_Inittab[] = { {"_signal", PyInit__signal}, {"_sysconfig", PyInit__sysconfig}, {"time", PyInit_time}, + {"_templatelib", PyInit__templatelib}, {"_thread", PyInit__thread}, {"_tokenize", PyInit__tokenize}, {"_types", PyInit__types}, diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index d12c5f9f32f265..6ea92f1dea3fcb 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -485,6 +485,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index acb4ab35dcad97..043814a305874e 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -708,6 +708,9 @@ Include\internal + + Include\internal + Include\cpython @@ -840,6 +843,9 @@ Include\internal + + Include\internal + Include\internal @@ -998,6 +1004,9 @@ Modules + + Modules + Modules diff --git a/configure b/configure index 1b75ddfa26dcdd..bd705bb52aa13b 100755 --- a/configure +++ b/configure @@ -785,6 +785,8 @@ MODULE__TYPING_FALSE MODULE__TYPING_TRUE MODULE__TYPES_FALSE MODULE__TYPES_TRUE +MODULE__TEMPLATELIB_FALSE +MODULE__TEMPLATELIB_TRUE MODULE__STRUCT_FALSE MODULE__STRUCT_TRUE MODULE_SELECT_FALSE @@ -31010,6 +31012,28 @@ then : +fi + + + if test "$py_cv_module__templatelib" != "n/a" +then : + py_cv_module__templatelib=yes +fi + if test "$py_cv_module__templatelib" = yes; then + MODULE__TEMPLATELIB_TRUE= + MODULE__TEMPLATELIB_FALSE='#' +else + MODULE__TEMPLATELIB_TRUE='#' + MODULE__TEMPLATELIB_FALSE= +fi + + as_fn_append MODULE_BLOCK "MODULE__TEMPLATELIB_STATE=$py_cv_module__templatelib$as_nl" + if test "x$py_cv_module__templatelib" = xyes +then : + + + + fi @@ -33747,6 +33771,10 @@ if test -z "${MODULE__STRUCT_TRUE}" && test -z "${MODULE__STRUCT_FALSE}"; then as_fn_error $? "conditional \"MODULE__STRUCT\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${MODULE__TEMPLATELIB_TRUE}" && test -z "${MODULE__TEMPLATELIB_FALSE}"; then + as_fn_error $? "conditional \"MODULE__TEMPLATELIB\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${MODULE__TYPES_TRUE}" && test -z "${MODULE__TYPES_FALSE}"; then as_fn_error $? "conditional \"MODULE__TYPES\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 diff --git a/configure.ac b/configure.ac index c449bb5ebb3cd4..8586fd48de0f8e 100644 --- a/configure.ac +++ b/configure.ac @@ -7787,6 +7787,7 @@ PY_STDLIB_MOD_SIMPLE([_queue]) PY_STDLIB_MOD_SIMPLE([_random]) PY_STDLIB_MOD_SIMPLE([select]) PY_STDLIB_MOD_SIMPLE([_struct]) +PY_STDLIB_MOD_SIMPLE([_templatelib]) PY_STDLIB_MOD_SIMPLE([_types]) PY_STDLIB_MOD_SIMPLE([_typing]) PY_STDLIB_MOD_SIMPLE([_interpreters])