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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4