[Python-Dev] Raising assertions on wrong element types in ElementTree
R. David Murray
rdmurray at bitdance.com
Fri Mar 16 16:33:09 CET 2012
On Fri, 16 Mar 2012 09:38:49 +0200, Eli Bendersky <eliben at gmail.com> wrote:
> 1. The behavior of append, insert and extend should be similar in this respect
> 2. AssertionError is not the customary error in such case - TypeError
> is much more suitable
> 3. The C implementation of ElementTree actually raises TypeError in
> all these methods, by virtue of using PyArg_ParseTuple
> 4. The Python implementation (at least in 3.2) actually doesn't raise
> even AssertionError in extend - this was commented out
>
> The suggestion for 3.3 (where compatibility between the C and Python
> implementations gets even more important, since the C one is now being
> imported by default when available) is to raise TypeError in all 3
> methods in the Python implementation, to match the C implementation,
> and to modify the documentation accordingly.
>
> There may appear to be a backwards compatibility here, since the doc
> of extend mentions raising AssertionError - but as said above, the doc
> is wrong, so no regressions in the code are be expected.
>
> Does that sound reasonable (for 3.3)?
Yes.
> Does it make sense to also fix this in 3.2/2.7? Or fix only the
> documentation? Or not touch them at all?
Our usual approach in cases like this is to not change it in the maint
releases. Why risk breaking someone's code for no particular benefit?
If you want some extra work you could add it as a deprecation warning,
I suppose.
--David
More information about the Python-Dev
mailing list