Issue 22949: fnmatch.translate doesn't add ^ at the beginning (original) (raw)

Created on 2014-11-26 14:34 by mstol, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
doc_fnmatch_translate.patch serhiy.storchaka,2016-10-16 12:52 review
Messages (8)
msg231712 - (view) Author: mstol (mstol) Date: 2014-11-26 14:34
I'm not sure if this is real bug, but the documentation of fnmatch.translate states: fnmatch.translate(pattern) Return the shell-style pattern converted to a regular expression. My intuition about shell-style pattern is that for example, pattern:t3 should match only t3, and not ost3 or xxxxxt3, but what I receive from fnmatch is: In [2]: fnmatch.translate("t3") Out[2]: 't3\\Z(?ms)' so using for example re.search will match not only on t3, but also on xxxt3 (in shell-like pattern is *t3). So... I believe it should be changed or at least the documentation should be more specific about what "shell-style pattern" mean.
msg231713 - (view) Author: mstol (mstol) Date: 2014-11-26 14:38
it can be changed easyly with changing the return statement in fnmatch.py function translate from: return res + '\Z(?ms)' to: return '^' + res + '\Z(?ms)'
msg231715 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-26 15:34
The result of fnmatch.translate() is used with re.match(). It could be even simplified if use it with re.fullmatch(), but I afraid such change can break user code.
msg231716 - (view) Author: mstol (mstol) Date: 2014-11-26 15:49
So you suggest that this output should not be used with re.search ? Why? I think it should be documented, or maybe it is? I know that this is not possible to introduce such a change to the currently used versions.
msg231718 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-26 15:54
I think it should be documented.
msg231722 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2014-11-26 17:59
I notice that it puts the inline flags at the end. It would be better to put them at the start.
msg278753 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-16 08:52
Since fnmatch.translate() uses scoped modifiers: r'(?s:%s)\Z' % res. Here is a patch that updates the documentation for fnmatch.translate().
msg279566 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-10-27 19:50
New changeset a1aef5f84142 by Serhiy Storchaka in branch '3.5': Issue #22949: Documented that fnmatch.translate() is for use with re.match(). https://hg.python.org/cpython/rev/a1aef5f84142 New changeset 8a564ab1d208 by Serhiy Storchaka in branch '2.7': Issue #22949: Documented that fnmatch.translate() is for use with re.match(). https://hg.python.org/cpython/rev/8a564ab1d208 New changeset dfda2f33fd08 by Serhiy Storchaka in branch '3.6': Issue #22949: Documented that fnmatch.translate() is for use with re.match(). https://hg.python.org/cpython/rev/dfda2f33fd08 New changeset d103ee917342 by Serhiy Storchaka in branch 'default': Issue #22949: Documented that fnmatch.translate() is for use with re.match(). https://hg.python.org/cpython/rev/d103ee917342
History
Date User Action Args
2022-04-11 14:58:10 admin set github: 67138
2016-10-27 19:51:16 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2016-10-27 19:50:50 python-dev set nosy: + python-devmessages: +
2016-10-16 12:52:35 serhiy.storchaka set files: + doc_fnmatch_translate.patchkeywords: + patch
2016-10-16 08:52:58 serhiy.storchaka set stage: needs patch -> patch reviewmessages: + versions: + Python 3.6, Python 3.7, - Python 3.4
2014-11-26 17:59:38 mrabarnett set messages: +
2014-11-26 15:54:15 serhiy.storchaka set priority: normal -> lowassignee: docs@pythoncomponents: + Documentationversions: + Python 3.4, Python 3.5keywords: + easynosy: + docs@pythonmessages: + stage: needs patch
2014-11-26 15:49:51 mstol set messages: +
2014-11-26 15:34:22 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2014-11-26 14:38:02 mstol set messages: +
2014-11-26 14:34:48 mstol create