On 11/22/06, Guido van Rossum <[EMAIL PROTECTED]> wrote:
> On 11/22/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote:
> > At 09:24 AM 11/22/2006 -0800, Bill Janssen wrote:
> > In Java, SMTP.sendmail would be something like this (using Python-like
> > syntax 'cause my Java is rusty):
> > def sendmail(self, from, to_addrs:str, msg, ...):
> > return self.sendmail(from_addr, [to_addrs], msg, ...)
> > def sendmail(self, from, to_addrs:list[str], msg, ...):
> > # main implementation
> Right. If this syntax was possible in Python lots of people would be
> very happy. But even the best generic function API I've seen is a lot
> more verbose than this -- there seems to be a separate set-up
> involved.
3rd-party registration is fundamental to extensible functions. The
best you can do is to minimize it.
def sendmail(self, from, to_addrs, msg, ...):
raise TypeError(to_addrs must be a string or list)
overload sendmail(self, from, to_addrs:str, msg, ...):
return self.sendmail(from_addr, [to_addrs], msg, ...)
overload sendmail(self, from, to_addrs:list[str], msg, ...):
# main implementation
And then someone else could write
overload smtplib.SMTP.sendmail(self, from, to_addrs:Seq[my_str], msg, ...):
to_addrs = [str(addr) for addr in to_addrs]
return smtplib.SMTP.sendmail(self, from, to_addrs:list[str], msg, ...)
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com