While using the re module in ipython I noticed an undocumented template function:
In [420]: re.template?
Type: function
Base Class: <type 'function'>
String Form: <function template at 0xb7eb8e64>
Namespace: Interactive
File: /usr/tideway/lib/python2.7/re.py
Definition: re.template(pattern, flags=0)
Docstring:
Compile a template pattern, returning a pattern object
there is also a flag re.TEMPLATE and its alias re.T.
None of this is mentioned in the docs for either 2.7 or 3.2. What do they do? Are they obsolete hangovers from an earlier version of Python, or an experimental feature that may be officially added in the future?
In CPython 2.7.1,
re.template()is defined as:_compilecalls_compile_typedwhich callssre_compile.compile. The only place in the code where theT(akaSRE_FLAG_TEMPLATE) flag is checked is in that function:This would have the effect of disabling all repetition operators (
*,+,?,{}etc):The way the code is structured (the unconditional
raisepreceding a bunch of dead code) makes me think that the feature was either never fully implemented, or has been turned off due to some problems. I can only guess what the intended semantics may have been.The end result is that the function does nothing useful.