Checking against NULL will be eliminated?
Philip Semanchuk
philip at semanchuk.com
Wed Mar 2 09:33:17 EST 2011
On Mar 2, 2011, at 9:21 AM, Stefan Behnel wrote:
> Claudiu Popa, 02.03.2011 14:51:
>> Hello Python-list,
>>
>>
>> I don't know how to call it, but the following Python 3.2 code seems to raise a
>> FutureWarning.
>>
>> def func(root=None):
>> nonlocal arg
>> if root:
>> arg += 1
>> The warning is "FutureWarning: The behavior of this method will change
>> in future versions. Use specific 'len(elem)' or 'elem is not None' test instead."
>> Why is the reason for this idiom to be changed?
>
> Let me guess - this is using ElementTree, right?
>
> It's not the idiom itself that changes, it's the Element class in ElementTree that will likely change its behaviour in later versions.
>
> Fix: do as it says.
And it's documented, although you might have a hard time finding it. See the "Caution" at the end of this section of documentation:
http://docs.python.org/py3k/library/xml.etree.elementtree.html#element-objects
I wish this behavior had been changed for Python 3.x. That warning has been in the ElementTree doc since before it became part of the standard lib, so it's not a new idea. Python 3.x seems like it would have been an ideal time to make the change. Oh well.
bye
P
More information about the Python-list
mailing list