D7296: pycompat: kludge around pytype being confused by __new__

2020-03-20 Thread durin42 (Augie Fackler)
durin42 added a comment.
durin42 planned changes to this revision.


  I'd like to get back to pytyping all the things, but I can't justify spending 
more time on it. If someone else wants to push things forward I'll gladly 
provide some mentorship.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: marmoute, yuja, mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2020-03-19 Thread marmoute (Pierre-Yves David)
marmoute added a comment.


  This is the last series stuck at the bottom of yadda.
  
  It feels like it is still a work in progress, @durin42 can you clarify the 
status of this and possibly move it out of need-review if it is still a work in 
progress ?

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: marmoute, yuja, mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2020-01-30 Thread marmoute (Pierre-Yves David)
marmoute added a comment.


  The status of this is unclear ? Are we waiting on:
  
  1. a the right way to do it in our codebase?
  2. a fix in pytype?
  3. a fix in python?
  4. something else?

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: marmoute, yuja, mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-19 Thread dlax (Denis Laxalde)
dlax added a comment.


  In D7296#109684 , @dlax wrote:
  
  > Looking closer at the error above, it mentions `bytestr.__init__`, not 
`__new__` (and there is in fact no type annotation for `__new__` in typeshed 
).
  
  https://github.com/python/typeshed/issues/2630

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: yuja, mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-19 Thread dlax (Denis Laxalde)
dlax added a comment.
dlax added a subscriber: yuja.


  In D7296#109683 , @durin42 wrote:
  
  > In D7296#109672 , @dlax wrote:
  >
  >> Sorry, still not ok afaict :/
  >
  > So, I tried fixing this and it actually made things worse? dagparser.py no 
longer typechecks if I correct the syntax? Try the pytype invocation from the 
test at the end of the series and you'll see what I mean.
  
  Ok, trying `pytype mercurial/dagparser.py` I get a couple of those errors:
  
File ".../mercurial/dagparser.py", line 172, in parsedag: Function 
bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
  Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: str)
  
  My point was that we need to keep "mercurial/pycompat.py" passing pytype 
before considering modules it depends on. Once the missing `type: ` is added 
and bytestr <-> _bytestr trick applied, it's okay but the error in dagparser.py 
persists...
  Looking closer at the error above, it mentions `bytestr.__init__`, not 
`__new__` (and there is in fact no type annotation for `__new__` in typeshed 
).
 So I suspect the "Callable" trick is not enough and we'd need a workaround 
similar to da925257 
 by 
@yuja .

INLINE COMMENTS

> pycompat.py:305
>  
> +bytestr = _bytestr  # Callable[[Union[bytes, str]], bytestr]
> +

Now the `type: ` is missing, so the comment is ignored.

Adding it, `pytype mercurial/pycompat.py` gives:

  mercurial/pycompat.py", line 305, in : Invalid type comment: 
Callable[[Union[bytes, str]], bytestr] [invalid-type-comment]
Name 'bytestr' is not defined

hence the kind of trick I suggested in my first comment on this line.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: yuja, mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-19 Thread durin42 (Augie Fackler)
durin42 added a comment.


  In D7296#109672 , @dlax wrote:
  
  > Sorry, still not ok afaict :/
  
  So, I tried fixing this and it actually made things worse? dagparser.py no 
longer typechecks if I correct the syntax? Try the pytype invocation from the 
test at the end of the series and you'll see what I mean.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-19 Thread durin42 (Augie Fackler)
durin42 updated this revision to Diff 18243.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7296?vs=18240=18243

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
@@ -48,6 +48,17 @@
 f.set_exception(exc_info[0])
 
 
+if not globals():  # hide this from non-pytype users
+from typing import (
+Callable,
+Union,
+)
+
+# keep pyflakes happy
+for t in (Callable, Union):
+assert t
+
+
 def identity(a):
 return a
 
@@ -154,7 +165,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)
@@ -291,6 +302,8 @@
 
 return w
 
+bytestr = _bytestr  # Callable[[Union[bytes, str]], bytestr]
+
 # these wrappers are automagically imported by hgloader
 delattr = _wrapattrfunc(builtins.delattr)
 getattr = _wrapattrfunc(builtins.getattr)
@@ -398,7 +411,7 @@
 unicode = unicode
 bytechr = chr
 byterepr = repr
-bytestr = str
+bytestr = str  # type: Callable[[Union[bytes, str]], bytestr]
 iterbytestr = iter
 maybebytestr = identity
 sysbytes = identity



To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-19 Thread dlax (Denis Laxalde)
This revision now requires changes to proceed.
dlax added a comment.
dlax requested changes to this revision.


  Sorry, still not ok afaict :/

INLINE COMMENTS

> pycompat.py:305
>  
> +bytestr = _bytestr  # type: Callable[[Union[bytes, str], bytestr]]
> +

`]` is still at the wrong place, I think. Should be `Callable[[Union[bytes, 
str]], bytestr]`.
Then I still get the "Name 'bytestr' is not defined" error mentioned above.

> pycompat.py:414
>  byterepr = repr
> -bytestr = str
> +bytestr = str  # type: Callable[[Union[bytes, str], bytestr]
>  iterbytestr = iter

same here about missing `]`.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-19 Thread durin42 (Augie Fackler)
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 18240.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7296?vs=18170=18240

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
@@ -48,6 +48,17 @@
 f.set_exception(exc_info[0])
 
 
+if not globals():  # hide this from non-pytype users
+from typing import (
+Callable,
+Union,
+)
+
+# keep pyflakes happy
+for t in (Callable, Union):
+assert t
+
+
 def identity(a):
 return a
 
@@ -154,7 +165,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)
@@ -291,6 +302,8 @@
 
 return w
 
+bytestr = _bytestr  # type: Callable[[Union[bytes, str], bytestr]]
+
 # these wrappers are automagically imported by hgloader
 delattr = _wrapattrfunc(builtins.delattr)
 getattr = _wrapattrfunc(builtins.getattr)
@@ -398,7 +411,7 @@
 unicode = unicode
 bytechr = chr
 byterepr = repr
-bytestr = str
+bytestr = str  # type: Callable[[Union[bytes, str], bytestr]
 iterbytestr = iter
 maybebytestr = identity
 sysbytes = identity



To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-18 Thread indygreg (Gregory Szorc)
indygreg added a comment.


  @durin42 I just queued most of the remaining patches in this series. This one 
still needs your attention, it appears.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-16 Thread dlax (Denis Laxalde)
This revision now requires changes to proceed.
dlax added inline comments.
dlax requested changes to this revision.

INLINE COMMENTS

> pycompat.py:294
>  
> +bytestr = _bytestr  # type: Callable[[Union[bytes, str], bytestr]
> +

A `]` is missing before `, bytestr`. Then, it's also missing `typing` imports.
But, even with this, I get:

  Invalid type comment: Callable[[Union[bytes, str]], bytestr] 
[invalid-type-comment]
Name 'bytestr' is not defined

I'm able to make this pass with:

  bytestr = _bytestr
  bytestr = bytestr  # type: Callable[[Union[bytes, str]], bytestr]

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-15 Thread durin42 (Augie Fackler)
durin42 updated this revision to Diff 18170.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7296?vs=18163=18170

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)
@@ -291,6 +291,8 @@
 
 return w
 
+bytestr = _bytestr  # type: Callable[[Union[bytes, str], bytestr]
+
 # these wrappers are automagically imported by hgloader
 delattr = _wrapattrfunc(builtins.delattr)
 getattr = _wrapattrfunc(builtins.getattr)
@@ -398,7 +400,7 @@
 unicode = unicode
 bytechr = chr
 byterepr = repr
-bytestr = str
+bytestr = str  # type: Callable[[Union[bytes, str], bytestr]
 iterbytestr = iter
 maybebytestr = identity
 sysbytes = identity



To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-15 Thread dlax (Denis Laxalde)
dlax added a comment.


  black complains because inline comments have only one space before (esp. the 
first one produces a parse error).
  LGTM otherwise.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-15 Thread durin42 (Augie Fackler)
durin42 updated this revision to Diff 18163.

REPOSITORY
  rHG Mercurial

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

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): # 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)
@@ -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



To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-15 Thread durin42 (Augie Fackler)
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=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

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



To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-15 Thread dlax (Denis Laxalde)
This revision now requires changes to proceed.
dlax added a comment.
dlax requested changes to this revision.


  Rather `class bytestr(bytes):  # type: Callable[[Union[bytes, str], bytestr]` 
as @yuya suggested in D7380 .

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg, dlax
Cc: mjpieters, dlax, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-14 Thread dlax (Denis Laxalde)
dlax added a comment.


class bytestr(bytes):  # type: (Union[bytes,str]) -> bytestr
  [...]
  
  Does this work?

REPOSITORY
  rHG Mercurial

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

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

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


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-13 Thread durin42 (Augie Fackler)
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=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


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-08 Thread indygreg (Gregory Szorc)
This revision now requires changes to proceed.
indygreg added a comment.
indygreg requested changes to this revision.


  I'm going to mark for revisions until we know more so this doesn't show up in 
the reviewable list.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-07 Thread durin42 (Augie Fackler)
durin42 added a comment.


  I've filed a bug with the pytype team, I'll report back.

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-07 Thread indygreg (Gregory Szorc)
indygreg added a comment.


  This one makes me sad because of potential performance regressions due to 
call overhead. I'd almost rather rip out Python 2 support rather than land 
this. But I could be convinced if pytypes is as cool as you say...
  
  Is there no way to annotate the types here without the call overhead? Could 
we do something like an `if False` trick to define a `def bytestr()` with the 
proper annotations? Surely there's got to be a way...

REPOSITORY
  rHG Mercurial

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

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

To: durin42, #hg-reviewers
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7296: pycompat: kludge around pytype being confused by __new__

2019-11-06 Thread durin42 (Augie Fackler)
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We add a function's worth of indirection to construction, but in so
  doing can properly annotate the factory function's types, obviating
  some annoying messes.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/pycompat.py
  mercurial/urllibcompat.py

CHANGE DETAILS

diff --git a/mercurial/urllibcompat.py b/mercurial/urllibcompat.py
--- a/mercurial/urllibcompat.py
+++ b/mercurial/urllibcompat.py
@@ -105,7 +105,7 @@
 def quote(s, safe=r'/'):
 # bytestr has an __iter__ that emits characters. quote_from_bytes()
 # does an iteration and expects ints. We coerce to bytes to appease it.
-if isinstance(s, pycompat.bytestr):
+if isinstance(s, pycompat._bytestr):
 s = bytes(s)
 s = urllib.parse.quote_from_bytes(s, safe=safe)
 return s.encode('ascii', 'strict')
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(r'>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,8 @@
 return tempfile.NamedTemporaryFile(
 mode, bufsize, suffix=suffix, prefix=prefix, dir=dir, delete=delete
 )
+
+
+def bytestr(s=b''):
+# type: (Union[bytes,str]) -> _bytestr
+return _bytestr(s)



To: durin42, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel