Closed Benjamin-Loison closed 1 month ago
On my Linux Mint 22 Cinnamon Framework 13:
clear && time sudo grep -rn '\<match(' / --include '*.py' --color=always --exclude-dir={usr,lib,.local,.cache,.cargo,.sage,bitcoin-master,bitcoin,inaSpeechSegmenter,git,woob,yt-dlp,libraries,proc}
...
real 0m3.997s
user 0m0.006s
sys 0m0.008s
git commit -a
Replace `re.match` with `re.fullmatch`
See [Benjamin-Loison/cpython/issues/43](https://github.com/Benjamin-Loison/cpython/issues/43).
Would be nice to commit using the clipboard, see Benjamin_Loison/git/issues/84.
Should verify that only commit such replacements, not pending changes containing secrets for instance.
# Should maybe be `re.fullmatch`, see [Benjamin-Loison/cpython/issues/43](https://github.com/Benjamin-Loison/cpython/issues/43).
BFMTV_news_ticker_retrieval/src/commit/d6a54eab66dcceb44b7e44edcfc940ecd2ec5e12/main.py#L94
re.match('tes', 'test')
<re.Match object; span=(0, 3), match='tes'>
re.match('^tes$', 'test') is None
True
On my Fairphone 4 Termux:
clear && time grep -rn '\<match(' ~ --include '*.py' --color=always --exclude-dir={.cargo,yt-dlp,woob,android_vendor_lineage,android_frameworks_base,google-api-python-client,matrix-commander,LibreTranslate}
...
real 0m0.777s
user 0m0.179s
sys 0m0.591s
On Debian 12 GNOME Pegasus:
clear && time sudo grep -rn '\<match(' / --include '*.py' --color=always --exclude-dir={usr,lib,media,Mess,Mumble,GitHub,platform-tools_r29.0.6-windows,volatility-2.6,yt-dlp,Libs,volatility3-1.0.0,impacket,TTS-master,NBT-master,git,ic,bitcoin,android-studio,bitcoin-master,.cargo,tacotron-master,TTS-256ed6307ce04b1ccbe7c3591bdb6b564f000cf1,Homki}
...
real 0m2.827s
user 0m0.007s
sys 0m0.005s
On OverClock3000:
clear && time sudo grep -rn '\<match(' / --include '*.py' --color=always --exclude-dir={var,opt,venv,.cargo,synapse,.local,.rustup,lib,.cache,node_modules,vbox,rustdesk,vcpkg,usr}
...
real 0m2.584s
user 0m1.050s
sys 0m1.381s
On LemnosLife VPS:
clear && time sudo grep -rn '\<match(' / --include '*.py' --color=always --exclude-dir={usr,.local,venv}
...
real 0m0.792s
user 0m0.231s
sys 0m0.330s
On my phone, my laptop, my computer, LemnosLife VPS and OverClock3000.
https://docs.python.org/3.13/library/re.html#re.fullmatch
Output:
``` Help on function fullmatch in module re: fullmatch(pattern, string, flags=0) Try to apply the pattern to all of the string, returning a Match object, or None if no match was found. ```https://docs.python.org/3.13/library/re.html#re.match
Output:
``` Help on function match in module re: match(pattern, string, flags=0) Try to apply the pattern at the start of the string, returning a Match object, or None if no match was found. ```The only difference is at the start and to all of the string.
Pyzo states:
on my Linux Mint 22 Cinnamon Framework 13.
In my head as far as I remember there were
re.match
andre.findall
/re.search
, so by default allre.match
should be replaced withre.fullmatch
.Quickly verifying for each occurrence if the replacement makes sense would be nice.