[Python-ideas] Curly braces expansion in shell-like matcher modules
Antoine Pitrou
solipsis at pitrou.net
Tue Aug 17 15:03:58 CEST 2010
On Tue, 17 Aug 2010 14:13:26 +0200
Mathieu Bridon
<bochecha at fedoraproject.org> wrote:
>
> However, some concerns were raised about the fnmatch module not being
> the correct place to do that, if the goal is to mimic shell behavior.
> Expansion would have to be done before, generating the list of
> patterns that would then be given to fnmatch.
I don't think mimicking shell behaviour should be a design goal of
fnmatch or any other stdlib module. Shells are multiple and, besides,
users are generally not interested in reproducing shell behaviour when
they use Python; they simply are looking for useful functionality.
IMO, fnmatch is the right place for such an enhancement.
(and, as the doc states, “glob uses fnmatch() to match pathname
segments”).
> FWIW (i.e not much), my opinion is leaning towards implementing it in glob.py:
> - add '{' to the magic_check regex
> - in glob1 (which is called when the pattern 'has_magic'), expand the
> braces and then call fnmatch.filter() on each resulting pattern
>
> That would respect more what is done in shells like Bash, and it makes
> it also more straight-forward to implement.
It also introduces a bizarrely inconsistent behaviour in the
dubious name of compatibility. Let's not reproduce the quirks of Unix
shells, which are hardly a reference in beautiful UI and API design.
Regards
Antoine.
More information about the Python-ideas
mailing list