On Tue, Jul 31, 2012 at 5:25 AM, PJ Eby <p...@telecommunity.com> wrote: > On Mon, Jul 30, 2012 at 12:51 PM, Guido van Rossum <gu...@python.org> wrote: >> - Most importantly: calling len(obj) and catching TypeError can only >> be a substitute for the real implementation, which IMO ought to check >> for the presence of a tp_len slot. Alas, checking hasattr(obj, >> '__len__') doesn't quite cut it either, since this returns true for a >> class object that defines a __len__ method for its instances (the >> class itself doesn't have a length). > > This isn't the only place this pattern comes up; maybe a hasmethod() > function somewhere (builtin, operator, inspect?) for this would be a > good idea. (i.e., something that returns true only if the method is > for the instance.) > > (But perhaps that's a python-ideas topic, since it raises the question > of whether it should really be something more like instancehasattr(), > or whether it should be limited to special slots or something else.)
Yes, please redirect / repost; I read p-ideas too. It's an interesting topic, if very specialized. -- --Guido van Rossum (python.org/~guido) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com