D7296: pycompat: kludge around pytype being confused by __new__
dlax (Denis Laxalde)
phabricator at mercurial-scm.org
Tue Nov 19 20:10:14 UTC 2019
dlax added a comment.
dlax added a subscriber: yuja.
In D7296#109683 <https://phab.mercurial-scm.org/D7296#109683>, @durin42 wrote:
> In D7296#109672 <https://phab.mercurial-scm.org/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 <https://github.com/python/typeshed/blob/34d68ab0a2117a08fa221d3a10884f35cacf2cdc/stdlib/2and3/builtins.pyi#L559>). So I suspect the "Callable" trick is not enough and we'd need a workaround similar to da925257 <https://phab.mercurial-scm.org/rHGda925257a39e5797e5b2e35ce1d68e923ea8ddf2> 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 <module>: 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
More information about the Mercurial-devel
mailing list