[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-20 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> fixed
stage: commit review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-20 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 104c55bc2276 by Serhiy Storchaka in branch '3.4':
Issue #23681: Fixed Python 2 to 3 poring bugs.
https://hg.python.org/cpython/rev/104c55bc2276

New changeset 817f1f47824c by Serhiy Storchaka in branch 'default':
Issue #23681: Fixed Python 2 to 3 poring bugs.
https://hg.python.org/cpython/rev/817f1f47824c

New changeset 68e9cf0ae93d by Serhiy Storchaka in branch 'default':
Issue #23681: The -b option now affects comparisons of bytes with int.
https://hg.python.org/cpython/rev/68e9cf0ae93d

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-20 Thread Brett Cannon

Brett Cannon added the comment:

I did one final pass on the patch and only had wording comments, so tweak those 
and it LGTM. Assigned to Serhiy since it's obviously his patch. =)

Only other thing is to either open up a separate bug or at least apply the 
fixes to the stdlib in Python 3.4 as well as 3.5.

--
assignee: brett.cannon -> serhiy.storchaka
nosy: +larry
stage: patch review -> commit review
versions: +Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-20 Thread STINNER Victor

STINNER Victor added the comment:

> This will help when someone writes something like `b'abcd'[2] == b'c'`

What if someone writes line[-1] == 0 and line is a Unicode string? Should we 
emit a warning?

I patched locally PyUnicode_RichCompare() to emit a warning. Hum, there are 
*many* warnings in argparse, http.client, and many other modules. I don't think 
that it's a good idea. It looks common to use a string for a sentinel (ex: 
state = "UNKNOWN") and then store an int (ex: state = 0). So comparison need to 
check the type (ex: isinstance(state, str) and state == "UNKNOWN") which is 
verbose and annoying.

So no, we should not emit a warning :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

@Brett: Yes, the patch handles `42 == b'*'` as well.

@Victor: The problem in such code:

x = b'Array'
x[0] == b'A'


Added explicit tests for bytes on the right side of the comparison and replaced 
b'.'[0] to ord(b'.').

--
Added file: http://bugs.python.org/file38591/bytes_to_int_compare_2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-20 Thread STINNER Victor

STINNER Victor added the comment:

I didn't understand the issue.

$ python2
>>> b'A'[0] == 65
False

$ python3
Python 3.4.1 (default, Nov  3 2014, 14:38:10) 
>>> b'A'[0] == 65
True

Oh ok, now I get it: Python 2 and Python 3 behaves differently when comparing a 
string of a single byte and an integer.

Ok to raise a warning when -b command line option is used.

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-19 Thread Martin Panter

Changes by Martin Panter :


--
nosy: +vadmium

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-19 Thread Paul Moore

Paul Moore added the comment:

LGTM, just one minor comment in review.

--
nosy: +paul.moore

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Berker Peksag

Berker Peksag added the comment:

> [...] fixes existing bugs in the stdlib and tests.

These changes should probably be backported to 3.4.

--
nosy: +berker.peksag

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Claudiu Popa

Changes by Claudiu Popa :


--
nosy: +Claudiu.Popa

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch that adds required feature and fixes existing bugs in the 
stdlib and tests.

No one of failed tests was false positive.

--
keywords: +patch
stage: test needed -> patch review
Added file: http://bugs.python.org/file38511/bytes_to_int_compare.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

6 tests failed:
test_buffer test_poplib test_quopri test_smtpd test_sunau
test_tokenize

And all of them look as bugs.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Brett Cannon

Changes by Brett Cannon :


--
versions: +Python 3.5 -Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Brett Cannon

Changes by Brett Cannon :


--
priority: normal -> deferred blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Brett Cannon

New submission from Brett Cannon:

To help writing Python 2/3 code the -b flag should switch on a warning when 
comparing an int to a bytes object in Python 2. This will help when someone 
writes something like `b'abcd'[2] == b'c'` and it always returns False thanks 
to the indexing returning 99 in Python 3.

--
assignee: brett.cannon
components: Interpreter Core
messages: 238228
nosy: brett.cannon
priority: normal
severity: normal
stage: test needed
status: open
title: Have -b warn when directly comparing ints and bytes
type: enhancement
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23681] Have -b warn when directly comparing ints and bytes

2015-03-16 Thread Brett Cannon

Changes by Brett Cannon :


--
priority: deferred blocker -> release blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com