Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mercurial/mercurial-devel
1 result
Show changes
Commits on Source (8)
  • Matt Harbison's avatar
    9be765b82a90
  • Matt Harbison's avatar
    typing: add missing signature for mercurial.cext.parsers.parse_index2() · df5d3b0d6472
    Matt Harbison authored
    Flagged by pytype 2022.11.18 when the cext stubs are made visible to it.  There
    are very likely other signatures that are missing, but this is enough to keep it
    happy for now.
    df5d3b0d6472
  • Matt Harbison's avatar
    typing: add py.typed to mercurial.cext for PEP 561 support · 2e34ea45aaea
    Matt Harbison authored
    Unfortunately, pytype doesn't support this yet.  But it was included with the
    attr package, so we might as well do it here for consistency.  Unlike the attr
    package, these type hints are only partial, so they are marked as such[1] (but
    who knows if it matters, given these are C extensions, so no local source code
    to scan).
    
    [1] https://peps.python.org/pep-0561/#partial-stub-packages
    2e34ea45aaea
  • Matt Harbison's avatar
    contrib: update check-pytype.sh to list stubs that caused pytype to crash · 3e1869751cfe
    Matt Harbison authored
    The same logic is in the TortoiseHg tests for running pytype, and it's useful to
    know if a new version of pytype is better or worse.
    3e1869751cfe
  • Matt Harbison's avatar
    contrib: add a script for adding vendored type stubs to typeshed · 03792c1ed341
    Matt Harbison authored
    I really hate this, but pytype doesn't support PEP 561 and doesn't seem to have
    the equivalent of `MYPYPATH` to point to custom stubs.  Ignoring the vendored
    stubs isn't necessarily harmful, but pytype has been choking on the vendored
    attr package after pytype 2022.03.29 with errors like this:
    
        File "/mnt/c/Users/Matt/hg/mercurial/linelog.py", line 52, in __iter__: Built-in function iter was called with the wrong arguments [wrong-arg-types]
                 Expected: (collection: bytearray)
          Actually passed: (collection: mercurial.thirdparty.attr._make._CountingAttr)
    
        File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 143, in pack: Built-in function len was called with the wrong arguments [wrong-arg-types]
                 Expected: (obj: Sized)
          Actually passed: (obj: mercurial.thirdparty.attr._make._CountingAttr)
          Attributes of protocol Sized are not implemented on mercurial.thirdparty.attr._make._CountingAttr: __len__
        File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 144, in pack: No attribute 'rfind' on mercurial.thirdparty.attr._make._CountingAttr [attribute-error]
        File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 146, in pack: Built-in function len was called with the wrong arguments [wrong-arg-types]
                 Expected: (obj: Sized)
          Actually passed: (obj: mercurial.thirdparty.attr._make._CountingAttr)
          Attributes of protocol Sized are not implemented on mercurial.thirdparty.attr._make._CountingAttr: __len__
        File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 152, in pack: No attribute 'v2_data' on mercurial.thirdparty.attr._make._CountingAttr [attribute-error]
    
        File "/mnt/c/Users/Matt/hg/mercurial/util.py", line 2817, in go: unsupported operand type(s) for /: 'count: mercurial.thirdparty.attr._make._CountingAttr' and 'float: float' [unsupported-operands]
          No attribute '__truediv__' on 'count: mercurial.thirdparty.attr._make._CountingAttr' or '__rtruediv__' on 'float: float'
        Called from (traceback):
          line 2981, in __bytes__
    
    This is essentially the same hack we've been using in TortoiseHg to add the
    vendored PyQt5 stubs.  What I don't understand is pytype *still* generates *.pyi
    files under .pytype/pyi/mercurial/thirdparty/attr, even when the package is
    explicitly ignored in the pytype command line args.  But it avoids the errors,
    which means we aren't stuck on pytype==2022.03.29.
    
    https://github.com/google/pytype/issues/151
    03792c1ed341
  • Matt Harbison's avatar
    ci: run the script to add vendored type stubs to typeshed · 556efeea6dbf
    Matt Harbison authored
    Since CI runs from docker images, it doesn't matter that this mucks with the
    typeshed bundled with pytype.
    556efeea6dbf
  • Matt Harbison's avatar
    ci: bump pytype to 2022.11.18 · 86e398a3d598
    Matt Harbison authored
    No particular reason, other than the current build is fairly old.  It flagged a
    few more things (that weren't errors based on the logic around them), but OTOH,
    some of the pyi stubs it generates are less specific.
    86e398a3d598
  • Matt Harbison's avatar
    setup: include vendored 3rd party type stubs · 54421ef8a423
    Matt Harbison authored
    While pytype may not support PEP 561, PyCharm does, so having the stubs
    available means it can determine `foo = attr.ib(type=int)` means `foo` is an
    int.  This only applies when using Mercurial as a library, like with TortoiseHg
    development- PyCharm is already smart enough to use the *.pyi files in the
    Mercurial source tree when hacking on Mercurial itself.
    
    I left the mercurial.cext stubs out because it seems very low level, that 3rd
    parties shouldn't be using directly.
    54421ef8a423
...@@ -70,3 +70,6 @@ ...@@ -70,3 +70,6 @@
-x mercurial/wireprotoframing.py \ -x mercurial/wireprotoframing.py \
-x mercurial/wireprotov1peer.py \ -x mercurial/wireprotov1peer.py \
-x mercurial/wireprotov1server.py -x mercurial/wireprotov1server.py
echo 'pytype crashed while generating the following type stubs:'
find .pytype/pyi -name '*.pyi' | xargs grep -l '# Caught error' | sort
...@@ -89,7 +89,8 @@ ...@@ -89,7 +89,8 @@
- hg -R /tmp/mercurial-ci/ update `hg log --rev '.' --template '{node}'` - hg -R /tmp/mercurial-ci/ update `hg log --rev '.' --template '{node}'`
- cd /tmp/mercurial-ci/ - cd /tmp/mercurial-ci/
- make local PYTHON=$PYTHON - make local PYTHON=$PYTHON
- $PYTHON -m pip install --user -U libcst==0.3.20 pytype==2022.03.29 - $PYTHON -m pip install --user -U libcst==0.3.20 pytype==2022.11.18
- ./contrib/setup-pytype.sh
script: script:
- echo "Entering script section" - echo "Entering script section"
- sh contrib/check-pytype.sh - sh contrib/check-pytype.sh
......
#!/bin/bash
set -e
set -u
# Find the python3 setup that would run pytype
PYTYPE=`which pytype`
PYTHON3=`head -n1 ${PYTYPE} | sed -s 's/#!//'`
# Existing stubs that pytype processes live here
TYPESHED=$(${PYTHON3} -c "import pytype; print(pytype.__path__[0])")/typeshed/stubs
HG_STUBS=${TYPESHED}/mercurial
echo "Patching typeshed at $HG_STUBS"
rm -rf ${HG_STUBS}
mkdir -p ${HG_STUBS}
cat > ${HG_STUBS}/METADATA.toml <<EOF
version = "0.1"
EOF
mkdir -p ${HG_STUBS}/mercurial/cext ${HG_STUBS}/mercurial/thirdparty/attr
touch ${HG_STUBS}/mercurial/__init__.pyi
touch ${HG_STUBS}/mercurial/cext/__init__.pyi
touch ${HG_STUBS}/mercurial/thirdparty/__init__.pyi
ln -sf $(hg root)/mercurial/cext/*.{pyi,typed} \
${HG_STUBS}/mercurial/cext
ln -sf $(hg root)/mercurial/thirdparty/attr/*.{pyi,typed} \
${HG_STUBS}/mercurial/thirdparty/attr
...@@ -1938,4 +1938,7 @@ ...@@ -1938,4 +1938,7 @@
raise error.Abort( raise error.Abort(
_(b'old bundle types only supports v1 changegroups') _(b'old bundle types only supports v1 changegroups')
) )
# HG20 is the case without 2 values to unpack, but is handled above.
# pytype: disable=bad-unpacking
header, comp = bundletypes[bundletype] header, comp = bundletypes[bundletype]
...@@ -1941,4 +1944,6 @@ ...@@ -1941,4 +1944,6 @@
header, comp = bundletypes[bundletype] header, comp = bundletypes[bundletype]
# pytype: enable=bad-unpacking
if comp not in util.compengines.supportedbundletypes: if comp not in util.compengines.supportedbundletypes:
raise error.Abort(_(b'unknown stream compression type: %s') % comp) raise error.Abort(_(b'unknown stream compression type: %s') % comp)
compengine = util.compengines.forbundletype(comp) compengine = util.compengines.forbundletype(comp)
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
import collections import collections
from typing import (
cast,
)
from .i18n import _ from .i18n import _
from .thirdparty import attr from .thirdparty import attr
...@@ -247,7 +251,7 @@ ...@@ -247,7 +251,7 @@
# required to apply it. If we see this metadata, compare against what the # required to apply it. If we see this metadata, compare against what the
# repo supports and error if the bundle isn't compatible. # repo supports and error if the bundle isn't compatible.
if version == b'packed1' and b'requirements' in params: if version == b'packed1' and b'requirements' in params:
requirements = set(params[b'requirements'].split(b',')) requirements = set(cast(bytes, params[b'requirements']).split(b','))
missingreqs = requirements - requirementsmod.STREAM_FIXED_REQUIREMENTS missingreqs = requirements - requirementsmod.STREAM_FIXED_REQUIREMENTS
if missingreqs: if missingreqs:
raise error.UnsupportedBundleSpecification( raise error.UnsupportedBundleSpecification(
......
...@@ -76,3 +76,7 @@ ...@@ -76,3 +76,7 @@
def insert(self, rev: int) -> None: ... def insert(self, rev: int) -> None: ...
def shortest(self, node: bytes) -> int: ... def shortest(self, node: bytes) -> int: ...
# The IndexObject type here is defined in C, and there's no type for a buffer
# return, as of py3.11. https://github.com/python/typing/issues/593
def parse_index2(data: object, inline: object, format: int = ...) -> Tuple[object, Optional[Tuple[int, object]]]: ...
partial
...@@ -723,4 +723,5 @@ ...@@ -723,4 +723,5 @@
s = bytes(s) s = bytes(s)
# call underlying function of s.encode('string_escape') directly for # call underlying function of s.encode('string_escape') directly for
# Python 3 compatibility # Python 3 compatibility
# pytype: disable=bad-return-type
return codecs.escape_encode(s)[0] # pytype: disable=module-attr return codecs.escape_encode(s)[0] # pytype: disable=module-attr
...@@ -726,4 +727,5 @@ ...@@ -726,4 +727,5 @@
return codecs.escape_encode(s)[0] # pytype: disable=module-attr return codecs.escape_encode(s)[0] # pytype: disable=module-attr
# pytype: enable=bad-return-type
def unescapestr(s: bytes) -> bytes: def unescapestr(s: bytes) -> bytes:
...@@ -727,4 +729,5 @@ ...@@ -727,4 +729,5 @@
def unescapestr(s: bytes) -> bytes: def unescapestr(s: bytes) -> bytes:
# pytype: disable=bad-return-type
return codecs.escape_decode(s)[0] # pytype: disable=module-attr return codecs.escape_decode(s)[0] # pytype: disable=module-attr
...@@ -730,4 +733,5 @@ ...@@ -730,4 +733,5 @@
return codecs.escape_decode(s)[0] # pytype: disable=module-attr return codecs.escape_decode(s)[0] # pytype: disable=module-attr
# pytype: enable=bad-return-type
def forcebytestr(obj): def forcebytestr(obj):
......
...@@ -1607,6 +1607,10 @@ ...@@ -1607,6 +1607,10 @@
'mercurial.helptext.internals': [ 'mercurial.helptext.internals': [
'*.txt', '*.txt',
], ],
'mercurial.thirdparty.attr': [
'*.pyi',
'py.typed',
],
} }
......