RE: [Python-Dev] Re: AlternativeImplementationforPEP292:SimpleString Substitutions
From: Barry Warsaw
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.
Can't you do something like def substitute(self, *args, **kwds): if len(args) > 1: raise TypeError # mild hack... if len(args) == 1: mapping = args[0] mapping.update(kwds) else: mapping = kwds # etc... This avoids the use of a strangely-named positional argument, at the cost of a check for too many positional arguments (because the interpreter no longer does it) Paul. __________________________________________________________________________ This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. __________________________________________________________________________
On Mon, 2004-09-13 at 10:50, Moore, Paul wrote:
From: Barry Warsaw
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.
Can't you do something like
def substitute(self, *args, **kwds): if len(args) > 1: raise TypeError # mild hack... if len(args) == 1: mapping = args[0] mapping.update(kwds) else: mapping = kwds
# etc...
This avoids the use of a strangely-named positional argument, at the cost of a check for too many positional arguments (because the interpreter no longer does it)
Nice. That's a better hack IMO than the crappy argument name hack. Thanks, -Barry
participants (2)
-
Barry Warsaw
-
Moore, Paul