This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fnmatch.translate('*.txt') fails
Type: Stage: resolved
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, projetmbc, python-dev, r.david.murray, valhallasw, vstinner
Priority: normal Keywords: patch

Created on 2015-05-01 19:36 by projetmbc, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
default.diff valhallasw, 2015-05-01 20:16 review
Messages (8)
msg242346 - (view) Author: Christophe BAL (projetmbc) Date: 2015-05-01 19:36
Hello.

I find the following bug on Python 3.4.

>>> import fnmatch, re
>>> regex = fnmatch.translate('*.txt')
>>> regex
'.*\\.txt\\Z(?ms)'

The string regex should be '.*\\.txt$'.
msg242348 - (view) Author: Merlijn van Deen (valhallasw) * Date: 2015-05-01 19:42
As far as I can see, the regex is correct:

\Z
Matches only at the end of the string.

(?iLmsux)
The group matches the empty string; the letters set the corresponding flags: (...)
  - re.M (multi-line),
  - re.S (dot matches all)

See https://docs.python.org/3.4/library/re.html

Do you have an example where the regex does not match a file it should match (or matches a file it shouldn't)?
msg242349 - (view) Author: Christophe BAL (projetmbc) Date: 2015-05-01 19:52
Ok.

But in that case, the official documentation should be updated because it
saids that string regex is  *'.*\\.txt\\Z(?ms)'*  and not  *'.*\\.txt$'*.

On the other hand, using this writing seems a bit strange. The 2nd one
should do the job.

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a "Lycée" **and **Python **amateur developer*

2015-05-01 21:42 GMT+02:00 Merlijn van Deen <report@bugs.python.org>:

>
> Merlijn van Deen added the comment:
>
> As far as I can see, the regex is correct:
>
> \Z
> Matches only at the end of the string.
>
> (?iLmsux)
> The group matches the empty string; the letters set the corresponding
> flags: (...)
>   - re.M (multi-line),
>   - re.S (dot matches all)
>
> See https://docs.python.org/3.4/library/re.html
>
> Do you have an example where the regex does not match a file it should
> match (or matches a file it shouldn't)?
>
> ----------
> nosy: +valhallasw
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue24108>
> _______________________________________
>
msg242350 - (view) Author: Merlijn van Deen (valhallasw) * Date: 2015-05-01 20:16
They are subtly different; the new regex also matches filenames with newlines, the old one doesn't (see Issue #6665 [1]).

Patch (although crazily minor) attached. With some fuzz, it applies on everything from 2.6..default.

[1] https://bugs.python.org/issue6665
msg242353 - (view) Author: Christophe BAL (projetmbc) Date: 2015-05-01 20:58
You're totally wrong and I am wrong.

There is still the tiny problem of the documentation.

Thanks for all.

*Christophe BAL*
*Enseignant de mathématiques en Lycée **et développeur Python amateur*
*---*
*French math teacher in a "Lycée" **and **Python **amateur developer*

2015-05-01 22:16 GMT+02:00 Merlijn van Deen <report@bugs.python.org>:

>
> Merlijn van Deen added the comment:
>
> They are subtly different; the new regex also matches filenames with
> newlines, the old one doesn't (see Issue #6665 [1]).
>
> Patch (although crazily minor) attached. With some fuzz, it applies on
> everything from 2.6..default.
>
> [1] https://bugs.python.org/issue6665
>
> ----------
> assignee:  -> docs@python
> components: +Documentation -asyncio
> keywords: +patch
> nosy: +docs@python
> Added file: http://bugs.python.org/file39261/default.diff
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue24108>
> _______________________________________
>
msg242354 - (view) Author: Christophe BAL (projetmbc) Date: 2015-05-01 21:04
Oups, sorry I want to say that you are totally RIGHT, and I am definitely
WRONG. :-)
msg242424 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-05-02 19:09
New changeset c5c65ef84a77 by R David Murray in branch '3.4':
#24108: Update fnmatch.translate example to show correct output.
https://hg.python.org/cpython/rev/c5c65ef84a77

New changeset cc6aed8ecb0d by R David Murray in branch 'default':
Merge: #24108: Update fnmatch.translate example to show correct output.
https://hg.python.org/cpython/rev/cc6aed8ecb0d

New changeset 5d356223f075 by R David Murray in branch '2.7':
#24108: Update fnmatch.translate example to show correct output.
https://hg.python.org/cpython/rev/5d356223f075
msg242425 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-02 19:10
Thanks Christophe and Merlijn.
History
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68296
2015-05-02 19:10:55r.david.murraysetstatus: open -> closed

versions: + Python 2.7, Python 3.5
nosy: + r.david.murray

messages: + msg242425
resolution: fixed
stage: resolved
2015-05-02 19:09:49python-devsetnosy: + python-dev
messages: + msg242424
2015-05-01 21:14:29gvanrossumsetnosy: - gvanrossum
2015-05-01 21:04:12projetmbcsetmessages: + msg242354
2015-05-01 20:58:11projetmbcsetmessages: + msg242353
2015-05-01 20:16:46valhallaswsetfiles: + default.diff

assignee: docs@python
components: + Documentation, - asyncio

keywords: + patch
nosy: + docs@python
messages: + msg242350
2015-05-01 19:54:12yselivanovsetnosy: - yselivanov
2015-05-01 19:52:22projetmbcsetmessages: + msg242349
2015-05-01 19:42:47valhallaswsetnosy: + valhallasw
messages: + msg242348
2015-05-01 19:36:55projetmbccreate