Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 49248:63fd0282ad40
node: stop converting binascii.Error to TypeError in bin()
Changeset f574cc00831a introduced the wrapper, to make bin() behave like on
Python 2, where it raised TypeError in many cases. Another previous approach,
changing callers to catch binascii.Error in addition to TypeError, was backed
out after negative review feedback [1].
However, I think it?s worth reconsidering the approach. Now that we?re on
Python 3 only, callers have to catch only binascii.Error instead of both.
Catching binascii.Error instead of TypeError has the advantage that it?s less
likely to cover a programming error (e.g. passing an int to bin() raises
TypeError). Also, raising TypeError never made sense semantically when bin()
got an argument of valid type.
As a side-effect, this fixed an exception in test-http-bad-server.t. The TODO
was outdated: it was not an uncaught ValueError in batch.results() but uncaught
TypeError from the now removed wrapper. Now that bin() raises binascii.Error
instead of TypeError, it gets converted to a proper error in
wirepeer.heads.<locals>.decode() that catches ValueError (superclass of
binascii.Error). This is a good example of why this changeset is a good idea.
Catching TypeError instead of ValueError there would not make much sense.
[1] https://phab.mercurial-scm.org/D2244
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Mon, 30 May 2022 16:18:12 +0200 |
parents | f254fc73d956 |
children | 127d33e63d1a |
comparison
equal
deleted
inserted
replaced
49247:3e5f1fb2aec7 | 49248:63fd0282ad40 |
---|---|
4 # | 4 # |
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 | 8 |
9 import binascii | |
9 import re | 10 import re |
10 | 11 |
11 from .i18n import _ | 12 from .i18n import _ |
12 from .pycompat import getattr | 13 from .pycompat import getattr |
13 from .node import ( | 14 from .node import ( |
1726 if len(n) == 2 * repo.nodeconstants.nodelen: | 1727 if len(n) == 2 * repo.nodeconstants.nodelen: |
1727 try: | 1728 try: |
1728 rn = repo.changelog.rev(bin(n)) | 1729 rn = repo.changelog.rev(bin(n)) |
1729 except error.WdirUnsupported: | 1730 except error.WdirUnsupported: |
1730 rn = wdirrev | 1731 rn = wdirrev |
1731 except (LookupError, TypeError): | 1732 except (binascii.Error, LookupError): |
1732 rn = None | 1733 rn = None |
1733 else: | 1734 else: |
1734 try: | 1735 try: |
1735 pm = scmutil.resolvehexnodeidprefix(repo, n) | 1736 pm = scmutil.resolvehexnodeidprefix(repo, n) |
1736 if pm is not None: | 1737 if pm is not None: |