[issue40480] "fnmatch" exponential execution time
kleshni added the comment: >So the solution is to replace multiple asterisks with a single one No, this is not a solution. This glob also hangs: fnmatch.fnmatchcase("a" * 32, "*a" * 16 + "b") And again, Bash and SQLite 3 work perfectly. -- ___ Python tracker <https://bugs.python.org/issue40480> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40480] "fnmatch" exponential execution time
New submission from kleshni : Hello. The following code hangs: import fnmatch fnmatch.fnmatchcase("a" * 32, "*" * 16 + "b") Measurements show that its execution time rises exponentially with the number of asterisks. Bash and SQLite 3 process this glob instantly. This is because "fnmatchcase" generates a regular expression with repeated dots: (?s:.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*b)\\Z It's equivalent to: (?s:.*b)\\Z But works in exponential time. So the solution is to replace multiple asterisks with a single one, so the latter regexp is generated instead. -- components: Library (Lib) messages: 367963 nosy: kleshni priority: normal severity: normal status: open title: "fnmatch" exponential execution time type: performance versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue40480> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com