[Python-Dev] Re: Alternative ImplementationforPEP292:SimpleString Substitutions (original) (raw)
Barry Warsaw barry at python.org
Mon Sep 13 16:32:55 CEST 2004
- Previous message: [Python-Dev] Re: Re: Alternative ImplementationforPEP292:SimpleStringSubstitutions
- Next message: [Python-Dev] Re: Re: Alternative Implementation forPEP292:SimpleString Substitutions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 2004-09-10 at 18:22, Raymond Hettinger wrote:
> My only problem with that is the interference that the 'mapping' > argument presents. IOW, kwds can't contain 'mapping'.
To support a case where both a mapping and keywords are present, perhaps an auxiliary class could simplify matters: def substitute(self, mapping=None, **kwds): if mapping is None: mapping = kwds elif kwds: mapping = altmap(kwds, mapping) . . . class altmap: def init(self, primary, secondary): self.primary = primary self.secondary = secondary def getitem(self, key): try: return self.primary[key] except KeyError: return self.secondary[key]
This matches the way keywords are used with the dict().
This isn't exactly what I was concerned about, but I agree that it's a worthwhile approach. (I'm going to accept your patch and check it in, with slight modifications.)
What I was worried about was if you providing 'mapping' positionally, and kwds contained a 'mapping' key, you'll get a TypeError. I'm going to change the positional argument to '__mapping' so collisions of that kind are less likely, and will document it in libstring.tex.
-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/20040913/c4d9e37d/attachment.pgp
- Previous message: [Python-Dev] Re: Re: Alternative ImplementationforPEP292:SimpleStringSubstitutions
- Next message: [Python-Dev] Re: Re: Alternative Implementation forPEP292:SimpleString Substitutions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]