This is an archive of the discontinued Mercurial Phabricator instance.

py3: replace %s by %r on binary format string when needed
AbandonedPublic

Authored by matclab on Nov 22 2019, 7:04 AM.

Details

Reviewers
dlax
Group Reviewers
hg-reviewers
Summary

For some error, mercurial displays the type of a variable. However the
formatting string used was "%s" which is not compatible with type and lead
to an excpetion `TypeError: %b requires a bytes-like object, or an object that
implements bytes, not 'type'`.

Per pep-046, we replace "%s" with "%r" which stay compatible with python2 and
python3.

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

matclab created this revision.Nov 22 2019, 7:04 AM
dlax requested changes to this revision.Nov 22 2019, 8:04 AM
dlax added a subscriber: dlax.

nit: the actual PEP is pep-0461 (https://www.python.org/dev/peps/pep-0461/)

mercurial/localrepo.py
1571

The first %s was correct I think because changeid can be a bytes.

For the second one, if %r is the way to go (I'm not sure), maybe we can drop pycompat.sysstr()?

This revision now requires changes to proceed.Nov 22 2019, 8:04 AM
matclab abandoned this revision.Nov 22 2019, 8:26 AM
mercurial/localrepo.py
1571

I'm really dumb…
I encountered the problem in mercurial 5.2 and did the change in mercurial devel without checking that the problem still occurred. I guess that pycompat.sysstr() already solves the problem.
In my opinion %r is shorter and cleaner, but I don't think we need to bother.

Sorry for the noise. I will close the request.