Title: fnmatch regular expression can be improved
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Alberto Galera, r.david.murray
Priority: normal Keywords:

Created on 2015-11-25 14:43 by Alberto Galera, last changed 2015-11-25 15:06 by r.david.murray. This issue is now closed.

Messages (2)
msg255361 - (view) Author: Alberto Galera (Alberto Galera) Date: 2015-11-25 14:43
fnmatch reviewing the code I've noticed that the outcome of the regular expression all returns generated in the first result

            res = res + '.*'
            res = res + '.*?'

    return res + '\Z(?ms)'
    return res + '$(?ms)'

example test:

import re
import fnmatch

urls = ['example/l1/l2/',

regex = fnmatch.translate('example/*')
# 'example\\/.*\\Z(?ms)'
re.findall(regex, "\n".join(urls))
# return ['example/l1/l2/\nexample/l1/\nexample/l1/\nexample/l1/l2/l3/']

# suggested change 
re.findall('example\\/.*?$(?ms)', "\n".join(urls))
# return ['example/l1/l2/',
#         'example/l1/',
#         'example/l1/',
#         'example/l1/l2/l3/']
msg255362 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-11-25 15:06
That would be a backward incompatible behavior change.  The patterns are designed to be used on single filenames, not on newline separated filenames.
Date User Action Args
2015-11-25 15:06:27r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg255362

resolution: rejected
stage: resolved
2015-11-25 14:43:46Alberto Galeracreate