[Python-Dev] 'hasattr' is broken by design (original) (raw)

Tres Seaver tseaver at palladion.com
Mon Aug 23 17:58:58 CEST 2010


-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Guido van Rossum wrote:

On Mon, Aug 23, 2010 at 7:46 AM, Benjamin Peterson <benjamin at python.org> wrote:

2010/8/23 Yury Selivanov <yselivanov at gmail.com>:

1) I propose to change 'hasattr' behaviour in Python 3, making it to swallow only AttributeError exceptions (exactly like 'getattr'). Probably, Python 3.2 release is our last chance. I would be in support of that. I am cautiously in favor. The existing behavior is definitely a mistake and a trap. But it has been depended on for almost 20 years now. I recommend that you create a patch, apply it, run the entire stdlib test suite and see how much breaks. That will give you an idea of the damage to expect for 3rd party code.

Robust third-party code is written to avoid 'hasattr', for precisely this reason. Third-party code which relies on 'hasattr' to mask non-AttributeErrors is broken alreay (it just doesn't show the borkedness).

Tres. - --

Tres Seaver +1 540-429-0999 tseaver at palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkxymr0ACgkQ+gerLs4ltQ4rQwCgyHJmqt2TefCgX2di5aJ92pVh 26YAnjKrBrK3gMs7ddo2wHtpT+iq2Mbg =BFxu -----END PGP SIGNATURE-----



More information about the Python-Dev mailing list