Skip to content

Commit 7c89025

Browse files
authored
Merge branch 'main' into networkx-merge-from-python-type-stubs
2 parents 53989c5 + 6af8f28 commit 7c89025

File tree

720 files changed

+9964
-4864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

720 files changed

+9964
-4864
lines changed

.github/workflows/daily.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ env:
3030
jobs:
3131
stubtest-stdlib:
3232
name: "stubtest: stdlib"
33-
if: ${{ github.repository == 'python/typeshed' || github.event_name == 'workflow_dispatch' }}
33+
if: ${{ github.repository == 'python/typeshed' || github.event_name != 'schedule' }}
3434
runs-on: ${{ matrix.os }}
3535
strategy:
3636
matrix:
3737
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
38-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev"]
38+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
3939
fail-fast: false
4040

4141
steps:
@@ -50,12 +50,15 @@ jobs:
5050
check-latest: true
5151
- name: Install dependencies
5252
run: pip install -r requirements-tests.txt
53+
# Temporary to get @disjoint_base support; can remove once mypy 1.18 is released
54+
- name: Install mypy from git
55+
run: pip install git+https://github.com/python/mypy.git@116b92bae7b5dbf5e6bd36fd9b0c6804973e5554
5356
- name: Run stubtest
5457
run: python tests/stubtest_stdlib.py
5558

5659
stubtest-third-party:
5760
name: "stubtest: third party"
58-
if: ${{ github.repository == 'python/typeshed' || github.event_name == 'workflow_dispatch' }}
61+
if: ${{ github.repository == 'python/typeshed' || github.event_name != 'schedule' }}
5962
runs-on: ${{ matrix.os }}
6063
strategy:
6164
matrix:
@@ -73,7 +76,7 @@ jobs:
7376
stubs/**/METADATA.toml
7477
- name: Install dependencies
7578
run: pip install -r requirements-tests.txt
76-
- name: Run stubtest
79+
- name: Install required system packages
7780
shell: bash
7881
run: |
7982
PACKAGES=$(python tests/get_stubtest_system_requirements.py)
@@ -83,8 +86,6 @@ jobs:
8386
printf "Installing APT packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n"
8487
sudo apt-get update -q && sudo apt-get install -qy $PACKAGES
8588
fi
86-
87-
PYTHON_EXECUTABLE="xvfb-run python"
8889
else
8990
if [ "${{ runner.os }}" = "macOS" ] && [ -n "$PACKAGES" ]; then
9091
printf "Installing Homebrew packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n"
@@ -95,15 +96,21 @@ jobs:
9596
printf "Installing Chocolatey packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n"
9697
choco install -y $PACKAGES
9798
fi
98-
99+
fi
100+
- name: Run stubtest
101+
shell: bash
102+
run: |
103+
if [ "${{ runner.os }}" = "Linux" ]; then
104+
PYTHON_EXECUTABLE="xvfb-run python"
105+
else
99106
PYTHON_EXECUTABLE="python"
100107
fi
101108
102109
$PYTHON_EXECUTABLE tests/stubtest_third_party.py --ci-platforms-only --num-shards 4 --shard-index ${{ matrix.shard-index }}
103110
104111
stub-uploader:
105112
name: stub_uploader tests
106-
if: ${{ github.repository == 'python/typeshed' || github.event_name == 'workflow_dispatch' }}
113+
if: ${{ github.repository == 'python/typeshed' || github.event_name != 'schedule' }}
107114
runs-on: ubuntu-latest
108115
steps:
109116
- name: Checkout typeshed

.github/workflows/stubtest_stdlib.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
matrix:
3333
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
34-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev"]
34+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
3535
fail-fast: false
3636

3737
steps:
@@ -46,5 +46,8 @@ jobs:
4646
check-latest: true
4747
- name: Install dependencies
4848
run: pip install -r requirements-tests.txt
49+
# Temporary to get @disjoint_base support; can remove once mypy 1.18 is released
50+
- name: Install mypy from git
51+
run: pip install git+https://github.com/python/mypy.git@116b92bae7b5dbf5e6bd36fd9b0c6804973e5554
4952
- name: Run stubtest
5053
run: python tests/stubtest_stdlib.py

.github/workflows/stubtest_third_party.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,29 @@ jobs:
4848
stubs/**/METADATA.toml
4949
- name: Install dependencies
5050
run: pip install -r requirements-tests.txt
51-
- name: Run stubtest
51+
- name: Determine changed stubs
5252
shell: bash
5353
run: |
5454
# This only runs stubtest on changed stubs, because it is much faster.
5555
# Use the daily.yml workflow to run stubtest on all third party stubs.
5656
function find_stubs {
5757
git diff --name-only origin/${{ github.base_ref }} HEAD | \
5858
egrep ^stubs/ | cut -d "/" -f 2 | sort -u | \
59-
(while read stub; do [ -d "stubs/$stub" ] && echo "$stub" || true; done)
59+
(while read stub; do [ -d "stubs/$stub" ] && echo -n "$stub " || true; done)
6060
}
6161
STUBS=$(find_stubs || echo '')
62-
62+
echo "Changed stubs: $STUBS"
63+
echo "STUBS=$STUBS" >> $GITHUB_ENV
64+
- name: Install required system packages
65+
shell: bash
66+
run: |
6367
if [ -n "$STUBS" ]; then
64-
echo "Testing $STUBS..."
6568
PACKAGES=$(python tests/get_stubtest_system_requirements.py $STUBS)
66-
6769
if [ "${{ runner.os }}" = "Linux" ]; then
6870
if [ -n "$PACKAGES" ]; then
6971
printf "Installing APT packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n"
7072
sudo apt-get update -q && sudo apt-get install -qy $PACKAGES
7173
fi
72-
73-
PYTHON_EXECUTABLE="xvfb-run python"
7474
else
7575
if [ "${{ runner.os }}" = "macOS" ] && [ -n "$PACKAGES" ]; then
7676
printf "Installing Homebrew packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n"
@@ -81,7 +81,17 @@ jobs:
8181
printf "Installing Chocolatey packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n"
8282
choco install -y $PACKAGES
8383
fi
84+
fi
85+
fi
86+
- name: Run stubtest
87+
shell: bash
88+
run: |
89+
if [ -n "$STUBS" ]; then
90+
echo "Testing $STUBS..."
8491
92+
if [ "${{ runner.os }}" = "Linux" ]; then
93+
PYTHON_EXECUTABLE="xvfb-run python"
94+
else
8595
PYTHON_EXECUTABLE="python"
8696
fi
8797

.github/workflows/tests.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ jobs:
4242
strategy:
4343
matrix:
4444
platform: ["linux", "win32", "darwin"]
45-
# TODO (2025-05-10) "3.13.2" should be "3.14-dev", see below.
46-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.13.2"]
45+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
4746
fail-fast: false
4847
steps:
4948
- uses: actions/checkout@v4
5049
- uses: actions/setup-python@v5
5150
with:
5251
python-version: ${{ matrix.python-version }}
52+
allow-prereleases: true
5353
- uses: astral-sh/setup-uv@v6
5454
with:
5555
version-file: "requirements-tests.txt"
@@ -63,15 +63,9 @@ jobs:
6363
fi
6464
- name: Run mypy_test.py
6565
run: |
66-
# TODO: (2025-05-10) This is a bad hack to work around mypy crashing
67-
# when running on Python 3.14. See https://github.com/python/mypy/pull/19020.
68-
if [[ "${{ matrix.python-version }}" == "3.13.2" ]]; then
69-
MYPY_PY_VERSION="3.14"
70-
else
71-
# python-version can sometimes be pinned to a specific version or to "-dev", but
72-
# mypy understands only X.Y version numbers.
73-
MYPY_PY_VERSION=$(echo ${{ matrix.python-version }} | cut -d - -f 1 | cut -d . -f 1-2)
74-
fi
66+
# python-version can sometimes be pinned to a specific version or to "-dev", but
67+
# mypy understands only X.Y version numbers.
68+
MYPY_PY_VERSION=$(echo ${{ matrix.python-version }} | cut -d - -f 1 | cut -d . -f 1-2)
7569
python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${MYPY_PY_VERSION}
7670
7771
regression-tests:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ ignore = [
177177
"TRY003", # Avoid specifying long messages outside the exception class
178178
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
179179
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
180+
"PLC0205", # Sometimes __slots__ really is a string at runtime
180181
###
181182
# False-positives, but already checked by type-checkers
182183
###

requirements-tests.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Type checkers that we test our stubs against. These should always
22
# be pinned to a specific version to make failure reproducible.
3-
mypy==1.16.1
4-
pyright==1.1.403
3+
mypy==1.18.1
4+
pyright==1.1.405
55

66
# Libraries used by our various scripts.
7-
# TODO (2025-05-09): Installing this on Python 3.14 on Windows fails at
8-
# the moment.
9-
aiohttp==3.12.14; python_version < "3.14"
7+
aiohttp==3.12.15
108
# TODO (2025-05-09): No wheels exist for Python 3.14 yet, slowing down CI
119
# considerably and prone to fail.
1210
grpcio-tools>=1.66.2; python_version < "3.14" # For grpc_tools.protoc
@@ -16,8 +14,7 @@ pathspec>=0.11.1
1614
pre-commit
1715
# Required by create_baseline_stubs.py. Must match .pre-commit-config.yaml.
1816
ruff==0.12.2
19-
# TODO (2025-05-07): Dependency libcst doesn't support Python 3.14 yet.
20-
stubdefaulter==0.1.0; python_version < "3.14"
17+
stubdefaulter==0.1.0
2118
termcolor>=2.3
2219
tomli==2.2.1; python_version < "3.11"
2320
tomlkit==0.13.3

scripts/stubsabot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async def with_extracted_archive(
204204
with zipfile.ZipFile(body) as zf:
205205
return handler(zf)
206206
elif packagetype == "sdist":
207-
# sdist defaults to `.tar.gz` on Lunix and to `.zip` on Windows:
207+
# sdist defaults to `.tar.gz` on Linux and to `.zip` on Windows:
208208
# https://docs.python.org/3.11/distutils/sourcedist.html
209209
if release_to_download.filename.endswith(".tar.gz"):
210210
with tarfile.open(fileobj=body, mode="r:gz") as zf:

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
# Please keep sorted alphabetically
66

7-
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
8-
http.client.HTTPConnection.response_class # the actual type at runtime is abc.ABCMeta
97
importlib.abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility
108
importlib.abc.MetaPathFinder.find_spec # Not defined on the actual class, but expected to exist.
119
importlib.abc.PathEntryFinder.find_spec # Not defined on the actual class, but expected to exist.
1210
tkinter.simpledialog.[A-Z_]+
1311
tkinter.simpledialog.TclVersion
1412
tkinter.simpledialog.TkVersion
15-
tkinter.Text.count # stubtest somehow thinks that index1 parameter has a default value, but it doesn't in any of the overloads
13+
tarfile.TarInfo.__slots__ # it's a big dictionary at runtime and the dictionary values are a bit long
1614

1715

1816
# ===============================================================
@@ -183,6 +181,12 @@ _collections_abc.AsyncGenerator.__anext__
183181
_collections_abc.AsyncGenerator.aclose
184182
_collections_abc.AsyncIterator.__anext__
185183

184+
# Pretend typing.ByteString is a Union, to better match its documented semantics.
185+
# As a side effect, this changes the definition of collections.abc.ByteString, which is okay,
186+
# because it's not an ABC that makes any sense and was deprecated in 3.12
187+
_collections_abc\.ByteString
188+
typing\.ByteString
189+
186190
_collections_abc.Callable # Typing-related weirdness
187191
_collections_abc.Mapping.get # Adding None to the Union messed up mypy
188192
_collections_abc.Sequence.index # Supporting None in end is not mandatory
@@ -201,7 +205,6 @@ _markupbase.ParserBase.parse_marked_section
201205

202206
_pydecimal.* # See comments in file
203207
_typeshed.* # Utility types for typeshed, doesn't exist at runtime
204-
argparse.ArgumentParser.__init__ # stubtest doesn't recognise the runtime default (a class) as being compatible with a callback protocol (the stub annotation)
205208
argparse.Namespace.__getattr__ # The whole point of this class is its attributes are dynamic
206209

207210
# Runtime AST node runtime constructor behaviour is too loose.
@@ -218,8 +221,6 @@ argparse.Namespace.__setattr__ # should allow setting any attribute
218221

219222
ast.ImportFrom.level # None on the class, but never None on instances
220223
ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796
221-
_?asyncio.Future.__init__ # Usually initialized from c object
222-
asyncio.futures.Future.__init__ # Usually initialized from c object
223224

224225
# Condition functions are exported in __init__
225226
asyncio.Condition.acquire
@@ -230,7 +231,6 @@ asyncio.locks.Condition.locked
230231
asyncio.locks.Condition.release
231232

232233
builtins.memoryview.__contains__ # C type that implements __getitem__
233-
builtins.object.__init__ # default C signature is incorrect
234234
builtins.reveal_locals # Builtins that type checkers pretends exist
235235
builtins.reveal_type # Builtins that type checkers pretends exist
236236
builtins.type.__dict__ # read-only but not actually a property; stubtest thinks it's a mutable attribute.
@@ -260,8 +260,6 @@ configparser.SectionProxy.getint # SectionProxy get functions are set in __init
260260
contextlib.AbstractAsyncContextManager.__class_getitem__
261261
contextlib.AbstractContextManager.__class_getitem__
262262

263-
_?contextvars.Context.__init__ # C signature is broader than what is actually accepted
264-
265263
copy.PyStringMap # defined only in Jython
266264

267265
# The Dialect properties are initialized as None in Dialect but their values are enforced in _Dialect
@@ -329,9 +327,6 @@ importlib.machinery.ExtensionFileLoader.get_filename
329327
inspect.Parameter.__init__
330328
inspect.Signature.__init__
331329

332-
inspect.Parameter.empty # set as private marker _empty
333-
inspect.Signature.empty # set as private marker _empty
334-
335330
logging.LogRecord.__setattr__ # doesn't exist, but makes things easy if we pretend it does
336331

337332
# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
@@ -377,11 +372,6 @@ multiprocessing.queues.JoinableQueue.__init__
377372
multiprocessing.queues.Queue.__init__
378373
multiprocessing.queues.SimpleQueue.__init__
379374

380-
# alias for a class defined elsewhere,
381-
# mypy infers the variable has type `(*args) -> ForkingPickler`
382-
# but stubtest infers the runtime type as <class ForkingPickler>
383-
multiprocessing.reduction.AbstractReducer.ForkingPickler
384-
385375
# These methods are dynamically created after object initialization,
386376
# copied from a wrapped lock object. Stubtest doesn't think they exist
387377
# because of that.
@@ -406,7 +396,6 @@ os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all Pat
406396

407397
pickle._Pickler\..* # Best effort typing for undocumented internals
408398
pickle._Unpickler\..* # Best effort typing for undocumented internals
409-
_?queue.SimpleQueue.__init__ # C signature is broader than what is actually accepted
410399
shutil.rmtree # function with attributes, which we approximate with a callable protocol
411400
socketserver.BaseServer.get_request # Not implemented, but expected to exist on subclasses.
412401
ssl.PROTOCOL_SSLv2 # Depends on the existence and flags of SSL
@@ -466,7 +455,6 @@ typing._Final.__init_subclass__
466455
typing\.Protocol
467456
typing(_extensions)?\._TypedDict
468457
typing(_extensions)?\.Any.*
469-
typing(_extensions)?\.Generic
470458
typing(_extensions)?\.TypedDict
471459
typing_extensions\.ParamSpec.*
472460
typing_extensions\.TypeVar.*

stdlib/@tests/stubtest_allowlists/darwin-py310.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ===========
2-
# 3.9 to 3.11
3-
# ===========
1+
# =======
2+
# <= 3.11
3+
# =======
44

55
# Added in Python 3.10.15
66
email._header_value_parser.NLSET
@@ -41,6 +41,7 @@ xml.etree.cElementTree.XMLPullParser.flush
4141
xml.parsers.expat.XMLParserType.GetReparseDeferralEnabled
4242
xml.parsers.expat.XMLParserType.SetReparseDeferralEnabled
4343
xml.sax.expatreader.ExpatParser.flush
44+
zipfile.ZipInfo.__slots__
4445

4546

4647
# =============================================================

stdlib/@tests/stubtest_allowlists/darwin-py311.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ fcntl.F_OFD_SETLK
88
fcntl.F_OFD_SETLKW
99

1010

11-
# ===========
12-
# 3.9 to 3.11
13-
# ===========
11+
# =======
12+
# <= 3.11
13+
# =======
1414

15-
# Incompatible changes introduced in Python 3.11.10
16-
# (Remove once 3.11.10 becomes available for MacOS)
15+
# Added in Python 3.11.10
1716
email._header_value_parser.NLSET
1817
email._header_value_parser.SPECIALSNL
1918
email.errors.HeaderWriteError
@@ -30,3 +29,11 @@ _msi
3029
msilib(.[a-z]+)?
3130
ossaudiodev
3231
spwd
32+
33+
34+
# ================
35+
# Unclear problems
36+
# ================
37+
38+
# Added in 3.11.1, flagged by stubtest on Python < 3.14 for unknown reasons
39+
errno.ENOTCAPABLE

0 commit comments

Comments
 (0)