[Updated] D11466: typing: add a fake `__init__()` to bytestr to distract pytype

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Wed Sep 22 07:56:33 UTC 2021


Closed by commit rHG1fda8c9358ce: typing: add a fake `__init__()` to bytestr to distract pytype (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11466?vs=30340&id=30358

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11466/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D11466

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
@@ -222,6 +222,15 @@
         >>> assert type(t) is bytes
         """
 
+        # Trick pytype into not demanding Iterable[int] be passed to __new__(),
+        # since the appropriate bytes format is done internally.
+        #
+        # https://github.com/google/pytype/issues/500
+        if TYPE_CHECKING:
+
+            def __init__(self, s=b''):
+                pass
+
         def __new__(cls, s=b''):
             if isinstance(s, bytestr):
                 return s



To: mharbison72, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210922/1823d8d8/attachment-0002.html>


More information about the Mercurial-patches mailing list