[Python-Dev] Requesting pronouncement on PEP 0424 (original) (raw)

Guido van Rossum guido at python.org
Tue Jul 31 06:17:25 CEST 2012


On Tue, Jul 31, 2012 at 5:25 AM, PJ Eby <pje at telecommunity.com> wrote:

On Mon, Jul 30, 2012 at 12:51 PM, Guido van Rossum <guido at 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 tplen 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)



More information about the Python-Dev mailing list