Alex Martelli wrote: > On Apr 4, 2006, at 5:29 PM, Guido van Rossum wrote: > [excellent example, mostly snipped] > > Just for when this will be published/blogged (as it deserves to be!), > tiny nit: > >> if hasattr(obj, "__iter__"): >> return obj.__iter__() >> raise TypeError("Can't iterate over a %s object" % >> obj.__class__.__name__) > > I think we should check/get __iter__ from obj.__class__, not from obj > itself (new style classes only take special methods from the type, > not from the instance). This applies to other occurrences of this > pattern later, too. > >> def register(self, T, A): >> self.registry[T] = A > > Why not accept more than one type (for the same adapter) at one gulp? > > def register(self, A, *Ts): > for T in Ts: > self.registry[T] = A
Assuming isinstance(obj, tuple_of_types) will still work, the natural analog here would be: def register(self, T, A): if isinstance(T, tuple): for one_T in T: self.registry[one_T] = A else: self.registry[T] = A -- Ian Bicking | [EMAIL PROTECTED] | http://blog.ianbicking.org _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com