Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BytesWarnings triggerred by test suite #64562

Closed
Arfrever mannequin opened this issue Jan 23, 2014 · 19 comments
Closed

BytesWarnings triggerred by test suite #64562

Arfrever mannequin opened this issue Jan 23, 2014 · 19 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Arfrever
Copy link
Mannequin

Arfrever mannequin commented Jan 23, 2014

BPO 20363
Nosy @tarekziade, @merwok, @ambv, @berkerpeksag, @serhiy-storchaka
Files
  • issue20363_v3.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-03-12.20:59:53.685>
    created_at = <Date 2014-01-23.09:47:31.664>
    labels = ['type-bug', 'library']
    title = 'BytesWarnings triggerred by test suite'
    updated_at = <Date 2014-03-12.20:59:53.684>
    user = 'https://bugs.python.org/Arfrever'

    bugs.python.org fields:

    activity = <Date 2014-03-12.20:59:53.684>
    actor = 'eric.araujo'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-03-12.20:59:53.685>
    closer = 'eric.araujo'
    components = ['Library (Lib)']
    creation = <Date 2014-01-23.09:47:31.664>
    creator = 'Arfrever'
    dependencies = []
    files = ['33715']
    hgrepos = []
    issue_num = 20363
    keywords = ['patch']
    message_count = 19.0
    messages = ['208903', '208990', '208993', '208995', '208997', '209009', '209011', '209043', '209263', '209266', '209269', '210415', '210416', '210418', '211178', '211185', '213292', '213293', '213296']
    nosy_count = 7.0
    nosy_names = ['tarek', 'eric.araujo', 'Arfrever', 'lukasz.langa', 'python-dev', 'berker.peksag', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20363'
    versions = ['Python 3.3', 'Python 3.4']

    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 23, 2014

    [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))

    @Arfrever Arfrever mannequin added the stdlib Python modules in the Lib dir label Jan 23, 2014
    @ambv ambv self-assigned this Jan 23, 2014
    @ambv ambv added the type-bug An unexpected behavior, bug, or error label Jan 23, 2014
    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 23, 2014

    I think that repr could be used:
    str(bytes_instance) -> repr(bytes_instance)
    "%s" % bytes_instance -> "%r" % bytes_instance

    Any opinions?

    @ambv
    Copy link
    Contributor

    ambv commented Jan 23, 2014

    repr(bytestr)[1:-1] ;-)

    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 23, 2014

    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'

    @serhiy-storchaka
    Copy link
    Member

    I think that repr could be used:

    Agree.

    "{}".format(bytestr) -> "{!r}".format(bytestr)

    @berkerpeksag
    Copy link
    Member

    Here's a patch to silence BytesWarnings.

    @berkerpeksag berkerpeksag removed the type-bug An unexpected behavior, bug, or error label Jan 23, 2014
    @berkerpeksag berkerpeksag added the type-bug An unexpected behavior, bug, or error label Jan 23, 2014
    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 23, 2014

    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))

    @serhiy-storchaka
    Copy link
    Member

    And

    'print(hash(eval(%s.decode("utf-8"))))' % repr_.encode("utf-8")
    

    can be simplified to

    'print(hash(eval(%a)))' % repr_
    

    @berkerpeksag
    Copy link
    Member

    Thanks for the review, Arfrever and Serhiy. Here's a new patch.

    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 26, 2014

    The new patch has %s and %r reversed in Lib/distutils/command/register.py.

    @berkerpeksag
    Copy link
    Member

    Ah, my bad. Thanks Arfrever.

    @serhiy-storchaka
    Copy link
    Member

    LGTM.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 6, 2014

    New changeset 791674a74e47 by Serhiy Storchaka in branch '3.3':
    Issue bpo-20363. Fixed BytesWarning triggerred by test suite.
    http://hg.python.org/cpython/rev/791674a74e47

    New changeset a4431dce107a by Serhiy Storchaka in branch 'default':
    Issue bpo-20363. Fixed BytesWarning triggerred by test suite.
    http://hg.python.org/cpython/rev/a4431dce107a

    @serhiy-storchaka
    Copy link
    Member

    Thank you Arfrever for your report. Thank you Berker for your patch.

    @merwok
    Copy link
    Member

    merwok commented Feb 13, 2014

    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?

    @serhiy-storchaka
    Copy link
    Member

    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.

    @merwok
    Copy link
    Member

    merwok commented Mar 12, 2014

    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.

    @merwok merwok reopened this Mar 12, 2014
    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Mar 12, 2014

    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.

    @merwok
    Copy link
    Member

    merwok commented Mar 12, 2014

    Thanks for correcting me. I created bpo-20900.

    @merwok merwok closed this as completed Mar 12, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants