[Python-Dev] Requesting pronouncement on PEP 0424
PJ Eby
pje at telecommunity.com
Tue Jul 31 05:25:28 CEST 2012
More information about the Python-Dev mailing list
Tue Jul 31 05:25:28 CEST 2012
- Previous message: [Python-Dev] Requesting pronouncement on PEP 0424
- Next message: [Python-Dev] Requesting pronouncement on PEP 0424
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 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.)
- Previous message: [Python-Dev] Requesting pronouncement on PEP 0424
- Next message: [Python-Dev] Requesting pronouncement on PEP 0424
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list