You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
3.11.0b1 regression: re.template removed without a deprecation period #92728
In Python 3.10, the re.template function exists and is not deprecated:
>>> import re
>>> re.template('', re.I)
re.compile('', re.TEMPLATE|re.IGNORECASE)
In Python 3.11.0b1 this function is gone:
>>> import re
>>> re.template('', re.I)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 're' has no attribute 'template'
This was removed in b09184bf05 without a depreciation period.
Despite being undocumented, projects actually use this function, see e.g. rpm-software-management/dnf#1827
However, I am not sure if I can revert the removal + deprecate after the feature freeze, or if I must only revert the removal in 3.11 and deprecate it in 3.12+. Will start with a PR to main anyway.
EDIT: I won't send a PR before there is a consensus.
If we decide to not revert the change, I suggest to document the removal in What's New in Python 3.11 and explain how to port impacted applications. For example, replace re.template() with re.compile().
If we decide to not revert the change, I suggest to document the removal in What's New in Python 3.11 and explain how to port impacted applications. For example, replace re.template() with re.compile().
I suppose we should do that even if we "just" deprecate it.
I have no opinion on this particular removal/deprecation, but just quickly want to point to PEP8 (https://peps.python.org/pep-0008/#public-and-internal-interfaces) and it's directive that: To better support introspection, modules should explicitly declare the names in their public API using the __all__ attribute. Setting __all__ to an empty list indicates that the module has no public API.. Previously, template was in __all__ which is also pre-faced with a # public symbols comment.
Perhaps there are reasons why this does not hold true for CPython, but it would be good if that could be documented somewhere. As a package maintainer I have recently been struggling to correctly determine what is and isn't public in a codebase that does not currently document this. So guidelines such as the one in the PEP and general agreement on those guidelines would be helpful for me and the wider ecosystem I think.
But if you think that it is worth, I am not opposing to reverting #32300 and adding a deprecation warning instead.
Yes, I believe that would be in the spirit of the policy. I will try to draft a PR shortly and then I will leave it for the others to decide if it's worth it.
Activity
Don't use undocumented re.template()
hroncok commentedon May 12, 2022
I intend to send a PR later today.However, I am not sure if I can revert the removal + deprecate after the feature freeze, or if I must only revert the removal in 3.11 and deprecate it in 3.12+. Will start with a PR to main anyway.
EDIT: I won't send a PR before there is a consensus.
vstinner commentedon May 12, 2022
Removal discussed at #91367
vstinner commentedon May 12, 2022
The discussion started in this larger issue about re "reorganization": #91308
vstinner commentedon May 12, 2022
I don't understand the purpose of the
re.template()function and there.TEMPLATEflag. It doesn't seem to disable backtracking:The only thing which seems to be changed is that repetition is not supported by TEMPLATE:
vstinner commentedon May 12, 2022
Code search for "TEMPLATE" in re/sre source code files of Python 3.10:
vstinner commentedon May 12, 2022
cc @serhiy-storchaka
hroncok commentedon May 12, 2022
To be honest, I don't understand the purpose of the
re.template()function either and I think that deprecating and removing it is a good thing.vstinner commentedon May 12, 2022
If we decide to not revert the change, I suggest to document the removal in What's New in Python 3.11 and explain how to port impacted applications. For example, replace
re.template()withre.compile().hroncok commentedon May 12, 2022
I suppose we should do that even if we "just" deprecate it.
9 remaining items
hugovk commentedon May 12, 2022
I don't find any
"re\.template\(in the top PypI 5,000 packages.GitHub's new search tool finds only 19 Python files matching
/\bre\.template\(/, many of which are forks or duplicates.DanielNoord commentedon May 13, 2022
I have no opinion on this particular removal/deprecation, but just quickly want to point to PEP8 (https://peps.python.org/pep-0008/#public-and-internal-interfaces) and it's directive that:
To better support introspection, modules should explicitly declare the names in their public API using the __all__ attribute. Setting __all__ to an empty list indicates that the module has no public API.. Previously,templatewas in__all__which is also pre-faced with a# public symbolscomment.Perhaps there are reasons why this does not hold true for
CPython, but it would be good if that could be documented somewhere. As a package maintainer I have recently been struggling to correctly determine what is and isn't public in a codebase that does not currently document this. So guidelines such as the one in the PEP and general agreement on those guidelines would be helpful for me and the wider ecosystem I think.hroncok commentedon May 24, 2022
Yes, I believe that would be in the spirit of the policy. I will try to draft a PR shortly and then I will leave it for the others to decide if it's worth it.
serhiy-storchaka commentedon May 24, 2022
How long the deprecation period should be? Would the only 3.11 be enough?
hroncok commentedon May 24, 2022
The policy speaks of 2 releases.
Revert "bpo-47211: Remove function re.template() and flag re.TEMPLATE (…
hroncok commentedon May 24, 2022
I've opened #93161
encukou commentedon May 24, 2022
@rhettinger:
I disagree.
Is this documented somewhere, or is it tribal knowledge (which should be documented, now that we have PEP-387 written)?
gh-92728: Restore re.template, but deprecate it (GH-93161)
pythongh-92728: Restore re.template, but deprecate it (pythonGH-93161)
gh-92728: Restore re.template, but deprecate it (GH-93161)
serhiy-storchaka commentedon May 25, 2022
Thank you @hugovk for your investigation and PR.
hugovk commentedon May 25, 2022
Thank you @hroncok for the PR ;)