We open-code encoding.unimethod here to avoid cycles, and do a local
import of encoding when someone str()s a RevlogError. It's not my
favorite solution, but it gets the job done.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
Comment Actions
class RevlogError(StorageError):
__bytes__ = _tobytes+ def str(self):
+ # avoid cycle, and directly implement unimethod for this
+ # str to allow delaying the import of encoding until
+ # someone actually wants the str of a RevlogError (which
+ # should be very rare).
+ from . import encoding
+ return encoding.unifromlocal(_tobytes(self))
It breaks str(err) on Python 2 because str shouldn't return a unicode
containing non-ASCII characters.
Suppose we just want to get rid of b''s on Python 3, we can add a helper
function like this:
if pycompat.ispy3: def _tostr(exc): return pycompat.sysstr(_tobytes(exc)) else: _tostr = Exception.__str__
It's safer than using encoding.unifromlocal() in that no other exception
will be raised on encoding error.