Some API suggestions

Issue #2 wontfix
Tshepang Lekhonkhobe
created an issue

This is my first ever API review, so be easy on me:

I don't like the fact that I do:

{{{ shell_call("ls {}", ".py") shell_call("ls {!u}", ".py") }}}

Instead of: {{{ shell_call("ls {}".format(".py")) shell_call("ls {}".format( ".py"), safe=False) }}}

  1. The "!u" is rather ugly, while the keyword thing is a lot more clear, even to someone who has never read the API (but is familiar with Python).

  2. I don't like the part that we are creating a custom interpolation mini-language, when str.format() already exists.

Perhaps I'm missing something?

Comments (4)

  1. Nick Coghlan repo owner

    The reason for using a custom string specifier rather than a separate argument is that the decision on whether quoting is needed or not should be made at the level of individual arguments, not the entire command invocation.

    In addition, the shell command invocation APIs already accept arbitrary keywork arguments (to support named parameters in the format strings), so there's nowhere to accept such a flag argument.

    Finally (on this point), the fact that bypassing the quoting looks ugly (and requires you to have read the docs to find out how to do it or understand what "!u" means) is actually a *positive* in my book - bypassing the quoting is a recipe for problems if you don't know what you're doing with it!

    As far as the mini-language goes, 99% of it *is* the standard library version (via string.StringFormatter). The automatic quoting (and the conversion specifier to request unquoted data) are the only additions.

  2. Log in to comment