Issue 20363: BytesWarnings triggerred by test suite
Created on 2014-01-23 09:47 by Arfrever, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue20363_v3.diff | berker.peksag, 2014-01-26 01:57 | review | ||
| Messages (19) | |||
|---|---|---|---|
| msg208903 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
Date: 2014-01-23 09:47 | |
[194/388] test_base64
/tmp/cpython/Lib/base64.py:365: BytesWarning: str() on a bytes instance
"by {} and {}".format(_A85START, _A85END))
...
[204/388] test_hash
/tmp/cpython/Lib/test/test_hash.py:175: BytesWarning: str() on a bytes instance
return 'print(hash(eval(%s.decode("utf-8"))))' % repr_.encode("utf-8")
...
[234/388] test_configparser
/tmp/cpython/Lib/configparser.py:289: BytesWarning: str() on a bytes instance
Error.__init__(self, 'Source contains parsing errors: %s' % source)
/tmp/cpython/Lib/configparser.py:326: BytesWarning: str() on a bytes instance
(filename, lineno, line))
...
[332/388/1] test_distutils
/tmp/cpython/Lib/distutils/command/register.py:303: BytesWarning: str() on a bytes instance
self.announce('%s%s%s' % (dashes, data, dashes))
|
|||
| msg208990 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
Date: 2014-01-23 20:36 | |
I think that repr could be used: str(bytes_instance) -> repr(bytes_instance) "%s" % bytes_instance -> "%r" % bytes_instance Any opinions? |
|||
| msg208993 - (view) | Author: Łukasz Langa (lukasz.langa) * ![]() |
Date: 2014-01-23 20:58 | |
`repr(bytestr)[1:-1]` ;-) |
|||
| msg208995 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
Date: 2014-01-23 21:11 | |
You rather meant [2:-1] instead of [1:-1], but if initial "b'" and final "'" are not needed in result string, then maybe just call .decode() on an instance of bytes. >>> str(b"xxx") "b'xxx'" >>> repr(b"xxx") "b'xxx'" >>> repr(b"xxx")[1:-1] "'xxx" >>> repr(b"xxx")[2:-1] 'xxx' >>> b"xxx".decode() 'xxx' |
|||
| msg208997 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2014-01-23 21:28 | |
> I think that repr could be used:
Agree.
"{}".format(bytestr) -> "{!r}".format(bytestr)
|
|||
| msg209009 - (view) | Author: Berker Peksag (berker.peksag) * ![]() |
Date: 2014-01-23 22:22 | |
Here's a patch to silence BytesWarnings. |
|||
| msg209011 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
Date: 2014-01-23 22:31 | |
I think that %s is better for 'dashes' variable (which is always str) in Lib/distutils/command/register.py: self.announce('%s%r%s' % (dashes, data, dashes)) |
|||
| msg209043 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2014-01-24 08:06 | |
And
'print(hash(eval(%s.decode("utf-8"))))' % repr_.encode("utf-8")
can be simplified to
'print(hash(eval(%a)))' % repr_
|
|||
| msg209263 - (view) | Author: Berker Peksag (berker.peksag) * ![]() |
Date: 2014-01-26 01:09 | |
Thanks for the review, Arfrever and Serhiy. Here's a new patch. |
|||
| msg209266 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
Date: 2014-01-26 01:37 | |
The new patch has %s and %r reversed in Lib/distutils/command/register.py. |
|||
| msg209269 - (view) | Author: Berker Peksag (berker.peksag) * ![]() |
Date: 2014-01-26 01:57 | |
Ah, my bad. Thanks Arfrever. |
|||
| msg210415 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2014-02-06 20:41 | |
LGTM. |
|||
| msg210416 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2014-02-06 20:57 | |
New changeset 791674a74e47 by Serhiy Storchaka in branch '3.3': Issue #20363. Fixed BytesWarning triggerred by test suite. http://hg.python.org/cpython/rev/791674a74e47 New changeset a4431dce107a by Serhiy Storchaka in branch 'default': Issue #20363. Fixed BytesWarning triggerred by test suite. http://hg.python.org/cpython/rev/a4431dce107a |
|||
| msg210418 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2014-02-06 20:58 | |
Thank you Arfrever for your report. Thank you Berker for your patch. |
|||
| msg211178 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2014-02-13 21:56 | |
Thanks for applying the patch. distutils tests don’t cover 100% of the codebase; did you test manually that the behavior of the changed code was still correct? |
|||
| msg211185 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2014-02-13 22:38 | |
At least it wasn't changed.
As I see, affected line is used to output debugging message (disabled by default). It produces different result in 2.7 and 3.x ("----------xxx----------" vs "----------b'xxx'----------") due to the difference between 2.x str and 3.x bytes.
|
|||
| msg213292 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2014-03-12 20:38 | |
I don’t understand one thing: you said the output wasn’t changed, then show an example of changed output: “"----------xxx----------" vs "----------b'xxx'----------"”. The “data” that is displayed is supposed to be text; showing “b'” and “'” is a regression for the 3.x line. |
|||
| msg213293 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
Date: 2014-03-12 20:44 | |
Output is different between Python 2 and 3, but not different between different versions in Python 3. Output in Python 3 is e.g. "----------b'xxx'----------" both before and after commit 791674a74e47. I suggest to create a separate issue for discussion about this message in distutils. |
|||
| msg213296 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2014-03-12 20:59 | |
Thanks for correcting me. I created #20900. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:57 | admin | set | github: 64562 |
| 2014-03-12 20:59:53 | eric.araujo | set | status: open -> closed messages: + msg213296 |
| 2014-03-12 20:44:22 | Arfrever | set | messages: + msg213293 |
| 2014-03-12 20:38:38 | eric.araujo | set | status: closed -> open messages: + msg213292 |
| 2014-02-13 22:38:47 | serhiy.storchaka | set | messages: + msg211185 |
| 2014-02-13 21:56:20 | eric.araujo | set | messages: + msg211178 |
| 2014-02-06 20:58:29 | serhiy.storchaka | set | status: open -> closed resolution: fixed messages: + msg210418 stage: commit review -> resolved |
| 2014-02-06 20:57:14 | python-dev | set | nosy:
+ python-dev messages: + msg210416 |
| 2014-02-06 20:41:11 | serhiy.storchaka | set | assignee: lukasz.langa -> serhiy.storchaka messages: + msg210415 stage: patch review -> commit review |
| 2014-01-26 01:58:41 | berker.peksag | set | files: - issue20363_v2.diff |
| 2014-01-26 01:57:21 | berker.peksag | set | files: - issue20363.diff |
| 2014-01-26 01:57:01 | berker.peksag | set | files:
+ issue20363_v3.diff messages: + msg209269 |
| 2014-01-26 01:37:36 | Arfrever | set | messages: + msg209266 |
| 2014-01-26 01:09:05 | berker.peksag | set | files:
+ issue20363_v2.diff messages: + msg209263 |
| 2014-01-24 08:06:05 | serhiy.storchaka | set | messages: + msg209043 |
| 2014-01-23 22:31:23 | Arfrever | set | messages: + msg209011 |
| 2014-01-23 22:22:58 | berker.peksag | set | assignee: lukasz.langa type: behavior stage: patch review |
| 2014-01-23 22:22:20 | berker.peksag | set | files:
+ issue20363.diff type: behavior -> (no value) keywords:
+ patch |
| 2014-01-23 21:28:27 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg208997 |
| 2014-01-23 21:11:40 | Arfrever | set | messages: + msg208995 |
| 2014-01-23 20:58:55 | lukasz.langa | set | messages: + msg208993 |
| 2014-01-23 20:36:08 | Arfrever | set | messages: + msg208990 |
| 2014-01-23 18:42:03 | lukasz.langa | set | assignee: lukasz.langa type: behavior stage: needs patch |
| 2014-01-23 09:48:19 | Arfrever | link | issue20361 dependencies |
| 2014-01-23 09:47:31 | Arfrever | create | |

