Patchwork D7296: pycompat: kludge around pytype being confused by __new__

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2019, 5:31 p.m.
Message ID <f0e9de53219c2a14339b435b21edc4fb@localhost.localdomain>
Download mbox | patch
Permalink /patch/43275/
State Not Applicable
Headers show

Comments

phabricator - Nov. 15, 2019, 5:31 p.m.
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 18161.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7296?vs=18066&id=18161

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




To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel

Patch

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): # type: Callable[[Union[bytes, str], bytestr]
         """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 # type: Callable[[Union[bytes, str], bytestr]
     iterbytestr = iter
     maybebytestr = identity
     sysbytes = identity
@@ -504,3 +504,12 @@ 
     return tempfile.NamedTemporaryFile(
         mode, bufsize, suffix=suffix, prefix=prefix, dir=dir, delete=delete
     )
+
+
+try:
+    if ispy3:
+        import typing
+
+        typing.Union
+except ImportError:
+    pass