[Python-3000] PEP 3137 plan of attack

Guido van Rossum guido at python.org
Tue Oct 9 17:56:50 CEST 2007


On 10/9/07, Thomas Lee <tom at vector-seven.com> wrote:
> Guido van Rossum wrote:
> >>>
> >>>> - make == and != between PyBytes and PyUnicode return False instead of
> >>>> raising TypeError
> >>>>
> >>>>
> Just thinking about it I'm pretty sure my initial patch is wrong -
> forgive my ignorance. To remove the ambiguity, is it fair to state the
> following?
>
> bytes() == str() -> False instead of raising TypeError
> bytes() != str() -> True instead of raising TypeError

Correct.

> I initially read that as "return False whenever any comparison between
> bytes and unicode objects is attempted" ...

The point is that a bytes and a str instance are never considered equal...

> > Assuming that PyUnicode_Compare is a three-way comparison (less,
> > equal, more), it should raise a TypeError when one of the arguments is
> > a PyString or PyBytes.
> >
> >
> Cool. Should have that sorted out soon. As above:
>
> str8() == str() -> False
> str8() != str() -> True
>
> Correct?

Well, in this case you actually have to compare the individual bytes.
But yes. ;-)

> >> Is it just me, or do string/bytes comparisons already work?
> >>
> >>  >>> s = str8('test')
> >>  >>> b = b'test'
> >>  >>> s == b
> >> True
> >>  >>> b == s
> >> True
> >>  >>> s != b
> >> False
> >>  >>> b != s
> >> False
> >>
> >
> > Seems it's already so. Do they order properly too? (< <= > >=)
> >
> Looks like it:
>
>  >>> str8('a') > b'b'
> False
>  >>> str8('a') < b'b'
> True
>  >>> str8('a') <= b'b'
> True
>  >>> str8('a') >= b'b'
> False

Well that part was easy then. ;-)


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list