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