[New-bugs-announce] [issue42353] Proposal: re.prefixmatch method (alias for re.match)
Gregory P. Smith
report at bugs.python.org
Fri Nov 13 14:27:03 EST 2020
New submission from Gregory P. Smith <greg at krypto.org>:
A well known anti-pattern in Python is use of re.match when you meant to use re.search.
re.fullmatch was added in 3.4 via https://bugs.python.org/issue16203 for similar reasons.
re.prefixmatch would be similar: we want the re.match behavior, but want the code to be obvious about its intent. This documents the implicit ^ in the name.
The goal would be to allow linters to ultimately flag re.match as the anti-pattern when in 3.10+ mode. Asking people to use re.prefixmatch or re.search instead.
This would help avoid bugs where people mean re.search but write re.match.
The implementation is trivial.
This is **not** a decision to deprecate the widely used in 25 years worth of code's re.match name. That'd be painful and is unlikely to be worth doing without spreading it over a 8+ year timeline.
----------
components: Library (Lib)
messages: 380928
nosy: gregory.p.smith
priority: normal
severity: normal
stage: needs patch
status: open
title: Proposal: re.prefixmatch method (alias for re.match)
type: enhancement
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42353>
_______________________________________
More information about the New-bugs-announce
mailing list