Inconsistent viewkeys behaviour

2014-04-28 Thread Joshua Landau
Is there any reference for this strange behaviour on Python 2:

 set()  dict().viewkeys()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can only compare to a set
 dict().viewkeys()  set()
False

?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent viewkeys behaviour

2014-04-28 Thread Terry Reedy

On 4/28/2014 2:22 AM, Joshua Landau wrote:

Is there any reference for this strange behaviour on Python 2:

  set()  dict().viewkeys()
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: can only compare to a set
  dict().viewkeys()  set()
 False


The left operand determines the result. The manual specifies that  and 
 do not have to be consistent. But I suspect that when 3.x dict.keys() 
was backported to 2.7.0, no one thought to update set, whereas the 
backported key view code already had the comparison.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent viewkeys behaviour

2014-04-28 Thread Gregory Ewing

Terry Reedy wrote:
The left operand determines the result. The manual specifies that  and 
  do not have to be consistent. But I suspect that when 3.x dict.keys() 
was backported to 2.7.0, no one thought to update set, whereas the 
backported key view code already had the comparison.


The question is why set() is raising an exception
instead of returning NotImplemented to give the
other operand a chance.

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list