Herald added a subscriber: mjpieters. durin42 updated this revision to Diff 18066.
REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7296?vs=17672&id=18066 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7296/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7296 AFFECTED FILES mercurial/pycompat.py CHANGE DETAILS diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -154,7 +154,7 @@ bytechr = struct.Struct('>B').pack byterepr = b'%r'.__mod__ - class bytestr(bytes): + class _bytestr(bytes): """A bytes which mostly acts as a Python 2 str >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1) @@ -208,7 +208,7 @@ """ def __new__(cls, s=b''): - if isinstance(s, bytestr): + if isinstance(s, _bytestr): return s if not isinstance( s, (bytes, bytearray) @@ -398,7 +398,7 @@ unicode = unicode bytechr = chr byterepr = repr - bytestr = str + _bytestr = str iterbytestr = iter maybebytestr = identity sysbytes = identity @@ -504,3 +504,29 @@ return tempfile.NamedTemporaryFile( mode, bufsize, suffix=suffix, prefix=prefix, dir=dir, delete=delete ) + + +try: + if ispy3: + import typing + + typing.Union +except ImportError: + pass + +# Hide this from non-pytype users. Note that when we're willing to +# depend on the `typing` module, we can remove the `if not globals` +# hack. +if ispy3 and 'typing' in globals(): + from typing import TYPE_CHECKING + + if typing.TYPE_CHECKING: + _bytestr = Any + + def bytestr(s=b''): + # type: (Union[bytes,str]) -> _bytestr + return _bytestr(s) + + +else: + bytestr = _bytestr To: durin42, #hg-reviewers, indygreg Cc: mjpieters, dlax, indygreg, mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel