[Python-Dev] Re: Alternative Implementation forPEP292:SimpleString Substitutions (original) (raw)
Barry Warsaw barry at python.org
Fri Sep 10 20:38:14 CEST 2004
- Previous message: [Python-Dev] Re: Alternative Implementation forPEP292:SimpleString Substitutions
- Next message: [Python-Dev] Re: Alternative ImplementationforPEP292:SimpleString Substitutions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 2004-09-10 at 01:50, Raymond Hettinger wrote:
[Barry] > And to make effbot and Raymond happy, it won't auto-promote to unicode > if everything's an 8bit string.
Glad to see that my happiness now ranks as a development objective ;-)
Well, if I want to get other work done... :)
> There will be updated unit tests, and I will update the documentation > and the PEP as appropriate -- if we've reached agreement on it.
+1 Beautiful job.
Cool!
The arguments against such reporting are: * Raymond is smoking crack. End users will never make this mistake. * The docs say python identifiers only. You blew it. Tough. Not a bug. * For someone who understands exactly what they are doing, perhaps $ma is the intended placeholder -- why force them to uses braces: ${ma}ñana.
It also makes it more difficult to document. IOW, right now the PEP and the documentation say that the first non-identifier character terminates the placeholder. How would you word the rules with your change?
In addition to the above usability issue, there is one other nit. The new invocation syntax offers us the opportunity for to also accept keyword arguments as mapping alternatives:
def substitute(self, mapping=None, **kwds): if mapping is None: mapping == kwds . . . When applicable, this makes for beautiful, readable calls: t.substitute(who="Barry", what="mailmeister", when=now()) This would be a simple and nice enchancement to Barry's excellent implementation. I recommend that keyword arguments be adopted.
My only problem with that is the interference that the 'mapping' argument presents. IOW, kwds can't contain 'mapping'. We could solve that in a couple of ways:
- ignore the problem and tell people not to do that
- change 'mapping' to something less likely to collide, such as '_mapping' or 'mapping', and then see #1.
- get rid of the mapping altogether and only have kwds. This would change the non-keyword invocation from
mytemplate.substitute(mymapping)
to
mytemplate.substitute(**mymapping)
A bit uglier and harder to document.
Note that there's also a potential collision on 'self'.
-Barry
-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 307 bytes Desc: This is a digitally signed message part Url : http://mail.python.org/pipermail/python-dev/attachments/20040910/20fd8f3e/attachment.pgp
- Previous message: [Python-Dev] Re: Alternative Implementation forPEP292:SimpleString Substitutions
- Next message: [Python-Dev] Re: Alternative ImplementationforPEP292:SimpleString Substitutions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]