Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

Equality testing

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


ethan at stoneleaf

May 18, 2011, 11:51 AM

Post #1 of 4 (563 views)
Permalink
Equality testing

In Python 3 inequality comparisons became forbidden.

--> 123 < [1, 2, 3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < list()

However, equality comparisons are still allowed

--> 123 == [1, 2, 3]
False

But you can't mix them (inequality wins)

--> 123 <= [1, 2, 3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() <= list()

I realize this is probably a Py4000 change if it happens at all, but
does this make sense? Shouldn't an attempt to compare to unlike objects
be a TypeError, just like trying to order them is?

It bit me when I tried to compare a byte string element with a single
character byte string (of course they should have matched, but since the
element was an int, the match was not longer True).

~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


benjamin at python

May 18, 2011, 12:22 PM

Post #2 of 4 (536 views)
Permalink
Re: Equality testing [In reply to]

2011/5/18 Ethan Furman <ethan [at] stoneleaf>:
> In Python 3 inequality comparisons became forbidden.
>
> --> 123 < [1, 2, 3]
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: unorderable types: int() < list()
>
> However, equality comparisons are still allowed
>
> --> 123 == [1, 2, 3]
> False
>
> But you can't mix them (inequality wins)
>
> --> 123 <= [1, 2, 3]
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: unorderable types: int() <= list()
>
> I realize this is probably a Py4000 change if it happens at all, but does
> this make sense?  Shouldn't an attempt to compare to unlike objects be a
> TypeError, just like trying to order them is?

No. Ordering for types which completely different doesn't make any
sense, but equality testing is just fine because it has an obvious
answer: no.



--
Regards,
Benjamin
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


tjreedy at udel

May 18, 2011, 2:01 PM

Post #3 of 4 (538 views)
Permalink
Re: Equality testing [In reply to]

On 5/18/2011 2:51 PM, Ethan Furman wrote:
> In Python 3 inequality comparisons became forbidden.
>
> --> 123 < [1, 2, 3]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: unorderable types: int() < list()
>
> However, equality comparisons are still allowed
>
> --> 123 == [1, 2, 3]
> False
>
> But you can't mix them (inequality wins)
>
> --> 123 <= [1, 2, 3]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: unorderable types: int() <= list()
>
> I realize this is probably a Py4000 change if it happens at all, but
> does this make sense? Shouldn't an attempt to compare to unlike objects
> be a TypeError, just like trying to order them is?
>
> It bit me when I tried to compare a byte string element with a single
> character byte string (of course they should have matched, but since the
> element was an int, the match was not longer True).

Questions/comments like this that are not about developing the next
versions of Python, as you acknowledge above, really belong elsewhere,
like on the ideas list.

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


ethan at stoneleaf

May 18, 2011, 2:42 PM

Post #4 of 4 (546 views)
Permalink
Re: Equality testing [In reply to]

Terry Reedy wrote:
> On 5/18/2011 2:51 PM, Ethan Furman wrote:
>> In Python 3 inequality comparisons became forbidden.
>>
>> --> 123 < [1, 2, 3]
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> TypeError: unorderable types: int() < list()
>>
>> However, equality comparisons are still allowed
>>
>> --> 123 == [1, 2, 3]
>> False
>>
>> But you can't mix them (inequality wins)
>>
>> --> 123 <= [1, 2, 3]
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> TypeError: unorderable types: int() <= list()
>>
>> I realize this is probably a Py4000 change if it happens at all, but
>> does this make sense? Shouldn't an attempt to compare to unlike objects
>> be a TypeError, just like trying to order them is?
>>
>> It bit me when I tried to compare a byte string element with a single
>> character byte string (of course they should have matched, but since the
>> element was an int, the match was not longer True).
>
> Questions/comments like this that are not about developing the next
> versions of Python, as you acknowledge above, really belong elsewhere,
> like on the ideas list.

My apologies. I'll be more careful.

~Ethan~

_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.