annotate contrib/setup-pytype.sh @ 51723:9367571fea21

cext: correct the argument handling of `b85encode()` The type stub indicated that this argument is `Optional`, which implies None is allowed. I don't see in the documentation where that's the case for `i`[1], and trying it in `hg debugshell` resulted in the method failing with a TypeError. I guess it was typed as an `int` argument because the `p` format unit wasn't added until Python 3.3[2]. In any event, 2 clients in core (`pvec` and `obsolete`) call this with no argument supplied, and `mdiff` calls it with True. So I guess we've avoided the None arg case, and when no arg is supplied, it defaults to the 0 initialization of the `pad` variable in C. Since the `p` format unit accepts both `int` and None, as well as `bool`, I'm not bothering to bump the module version- this code is more permissive than it was, in addition to being more correct. Interestingly, when I first imported the `cext` and `pure` methods in the same manner as the previous commit, it dropped the `Optional` part of the argument type when generating `util.pyi`. No idea why. [1] https://docs.python.org/3/c-api/arg.html#numbers [2] https://docs.python.org/3/c-api/arg.html#other-objects
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 20 Jul 2024 01:55:09 -0400
parents 832a1aeb576f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49652
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
1 #!/bin/bash
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
2
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
3 set -e
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
4 set -u
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
5
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
6 # Find the python3 setup that would run pytype
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
7 PYTYPE=`which pytype`
51711
832a1aeb576f pytype: only try the hacky way of finding PYTHON if not provided
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
8 PYTHON3=${PYTHON:-`head -n1 ${PYTYPE} | sed -s 's/#!//'`}
49652
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
9
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
10 # Existing stubs that pytype processes live here
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
11 TYPESHED=$(${PYTHON3} -c "import pytype; print(pytype.__path__[0])")/typeshed/stubs
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
12 HG_STUBS=${TYPESHED}/mercurial
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
13
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
14 echo "Patching typeshed at $HG_STUBS"
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
15
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
16 rm -rf ${HG_STUBS}
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
17 mkdir -p ${HG_STUBS}
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
18
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
19 cat > ${HG_STUBS}/METADATA.toml <<EOF
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
20 version = "0.1"
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
21 EOF
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
22
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
23
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
24 mkdir -p ${HG_STUBS}/mercurial/cext ${HG_STUBS}/mercurial/thirdparty/attr
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
25
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
26 touch ${HG_STUBS}/mercurial/__init__.pyi
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
27 touch ${HG_STUBS}/mercurial/cext/__init__.pyi
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
28 touch ${HG_STUBS}/mercurial/thirdparty/__init__.pyi
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
29
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
30 ln -sf $(hg root)/mercurial/cext/*.{pyi,typed} \
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
31 ${HG_STUBS}/mercurial/cext
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
32 ln -sf $(hg root)/mercurial/thirdparty/attr/*.{pyi,typed} \
03792c1ed341 contrib: add a script for adding vendored type stubs to typeshed
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
33 ${HG_STUBS}/mercurial/thirdparty/attr