diff --git a/hgext/fsmonitor/pywatchman/compat.py b/hgext/fsmonitor/pywatchman/compat.py --- a/hgext/fsmonitor/pywatchman/compat.py +++ b/hgext/fsmonitor/pywatchman/compat.py @@ -32,37 +32,22 @@ import sys """Compatibility module across Python 2 and 3.""" -PYTHON2 = sys.version_info < (3, 0) PYTHON3 = sys.version_info >= (3, 0) # This is adapted from https://bitbucket.org/gutworth/six, and used under the # MIT license. See LICENSE for a full copyright notice. -if PYTHON3: - - def reraise(tp, value, tb=None): - try: - if value is None: - value = tp() - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value - finally: - value = None - tb = None -else: - exec( - """ def reraise(tp, value, tb=None): try: - raise tp, value, tb + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value finally: + value = None tb = None -""".strip() - ) + -if PYTHON3: - UNICODE = str -else: - UNICODE = unicode # noqa: F821 We handled versioning above +UNICODE = str diff --git a/hgext/fsmonitor/pywatchman/pybser.py b/hgext/fsmonitor/pywatchman/pybser.py --- a/hgext/fsmonitor/pywatchman/pybser.py +++ b/hgext/fsmonitor/pywatchman/pybser.py @@ -51,17 +51,15 @@ BSER_TEMPLATE = b"\x0b" BSER_SKIP = b"\x0c" BSER_UTF8STRING = b"\x0d" -if compat.PYTHON3: - STRING_TYPES = (str, bytes) - unicode = str +STRING_TYPES = (str, bytes) +unicode = str + - def tobytes(i): - return str(i).encode("ascii") +def tobytes(i): + return str(i).encode("ascii") - long = int -else: - STRING_TYPES = (unicode, str) - tobytes = bytes + +long = int # Leave room for the serialization header, which includes # our overall length. To make things simpler, we'll use an @@ -87,7 +85,7 @@ def _int_size(x): def _buf_pos(buf, pos): ret = buf[pos] # Normalize the return type to bytes - if compat.PYTHON3 and not isinstance(ret, bytes): + if not isinstance(ret, bytes): ret = bytes((ret,)) return ret @@ -250,10 +248,7 @@ class _bser_buffer: else: raise RuntimeError("Cannot represent this mapping value") self.wpos += needed - if compat.PYTHON3: - iteritems = val.items() - else: - iteritems = val.iteritems() # noqa: B301 Checked version above + iteritems = val.items() for k, v in iteritems: self.append_string(k) self.append_recursive(v)