-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Stefan Behnel wrote:
Hi Fredrik,
Fredrik Lundh wrote:
Steve Howe wrote:
I know assert statements raise that, but no other Python function raises AssertionError on wrong parameters, right ? This is debug code. I mentioned an example where TypeError is raised instead of AssertionError. Is there a reason for not following the Python convention ? What other Python functions raise AssertionError instead of TypeError ?
any function that uses assert, which is the most efficient way to add *optional* assertions to code written in *Python*.
[snip]
why should a Python implementation of a library have to suffer because some built-in function is written in C?
Ok, so, if I understand that right, using AssertionError is an internal optimisation. It is only used to allow switching it off for performance reasons. (Note that you can't do that in C code.)
So, for exactly the same reason, lxml will continue to raise TypeError for both None values and other invalid argument types. The test is done internally by Pyrex anyway and therefore the cheapest solution.
According to your arguments, code that catches assertions is broken anyway, so this is not even an incompatibility.
That's good news.
I think the assertion was that catching AssertionError is broken, because the assertion failure is a *programming* error, not a *runtime* error. The TypeErrors raised from Pyrex probably fit the same way. More framework-y code sometimes ends up having to catch such errors, either for backwards compatibility or to allow for things like broken plugins. Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEbe4l+gerLs4ltQ4RArEKAJ98L2UYoQ/lXXScXx2p3IwXSu5/aQCeNYLG RnMvKP5qOg/GXoPojvqcOPw= =4rgO -----END PGP SIGNATURE-----