classification
Title: BytesWarning at compile time
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, inada.naoki, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2017-01-21 07:09 by serhiy.storchaka, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
constant-key-bytes-warning.patch serhiy.storchaka, 2017-01-21 08:06 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (6)
msg285940 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-21 07:09
BytesWarning can be raised during compilation.

$ ./python -Wa -b -c "lambda: 'a'; lambda: b'a'"
sys:1: BytesWarning: Comparison between bytes and string
sys:1: BytesWarning: Comparison between bytes and string
sys:1: BytesWarning: Comparison between bytes and string
sys:1: BytesWarning: Comparison between bytes and string

_PyCode_ConstantKey() should produce keys that don't allow comparing bytes with strings nested in tuples or frozensets. Currently it returns (tuple, ('a',), ((str, 'a'),)) for ('a',) and (tuple, (b'a',), ((bytes, b'a'),)) for (b'a',). Key tuples have the same size and the same first element. Comparing second elements emits a BytesWarning.
msg285943 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-21 08:06
Proposed patch fixes the issue.
msg286107 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2017-01-23 19:03
LGTM
msg286150 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2017-01-24 08:21
LGTM
msg286205 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-24 18:54
New changeset 2bd2ef1696cf by Serhiy Storchaka in branch '3.5':
Issue #29337: Fixed possible BytesWarning when compare the code objects.
https://hg.python.org/cpython/rev/2bd2ef1696cf

New changeset f6c327f2daa6 by Serhiy Storchaka in branch '3.6':
Issue #29337: Fixed possible BytesWarning when compare the code objects.
https://hg.python.org/cpython/rev/f6c327f2daa6

New changeset 00fb30d4905d by Serhiy Storchaka in branch 'default':
Issue #29337: Fixed possible BytesWarning when compare the code objects.
https://hg.python.org/cpython/rev/00fb30d4905d
msg286208 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-24 19:34
I'm surprised that removing the type from the key works. Since tests pass,
it's ok for me :-)

I'm happy that I spent time to write these tests, I'm now more confident
when this code is modified. Serhiy asked me to write these tests if I
recall correctly ;-)
History
Date User Action Args
2017-03-31 16:36:17dstufftsetpull_requests: + pull_request915
2017-01-24 19:34:00vstinnersetmessages: + msg286208
2017-01-24 18:55:22serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-01-24 18:54:49python-devsetnosy: + python-dev
messages: + msg286205
2017-01-24 08:21:07inada.naokisetmessages: + msg286150
2017-01-23 19:03:43brett.cannonsetnosy: + brett.cannon
messages: + msg286107
2017-01-21 08:06:43serhiy.storchakasetfiles: + constant-key-bytes-warning.patch
keywords: + patch
messages: + msg285943

stage: patch review
2017-01-21 07:09:46serhiy.storchakacreate