Skip to content

Commit 0e3704d

Browse files
authored
Merge branch 'main' into protobuf-decoder-factories
2 parents ffdc917 + 8baf5d8 commit 0e3704d

134 files changed

Lines changed: 1406 additions & 519 deletions

File tree

Some content is hidden

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

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ when running stubtest. For example: `mypy-plugins = ["mypy_django_plugin.main"]`
235235
* `mypy-plugins-config` (default: `{}`): A dictionary mapping plugin names to their
236236
configuration dictionaries for use by mypy plugins. For example:
237237
`mypy-plugins-config = {"django-stubs" = {"django_settings_module" = "@tests.django_settings"}}`
238+
* `install-environment` (default: `{}`): A dictionary of environment variables
239+
to set while `pip install`ing the package and its dependencies for stubtest.
240+
Useful for packages that read build-time options from the environment, for
241+
example to disable CPU-specific compiler flags that do not survive CI's
242+
shared wheel cache. For example:
243+
`install-environment = { HNSWLIB_NO_NATIVE = "1" }`
238244

239245
`*-dependencies` are usually packages needed to `pip install` the implementation
240246
distribution.
@@ -370,7 +376,7 @@ Use `@deprecated` if and only if
370376

371377
- a feature is deprecated at runtime (either using `@deprecated` or with a
372378
runtime warning); or
373-
- a feature is documented to be deprecated (e.g. in API documention,
379+
- a feature is documented to be deprecated (e.g. in API documentation,
374380
docstrings, or comments).
375381

376382
For standard library features that are not deprecated in all Python versions

lib/ts_utils/metadata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def _is_nested_dict(obj: object) -> TypeGuard[dict[str, dict[str, Any]]]:
5353
return isinstance(obj, dict) and all(isinstance(k, str) and isinstance(v, dict) for k, v in obj.items())
5454

5555

56+
def _is_dict_of_strings(obj: object) -> TypeGuard[dict[str, str]]:
57+
return isinstance(obj, dict) and all(isinstance(k, str) and isinstance(v, str) for k, v in obj.items())
58+
59+
5660
@functools.cache
5761
def get_oldest_supported_python() -> str:
5862
with PYPROJECT_PATH.open("rb") as config:
@@ -85,6 +89,7 @@ class StubtestSettings:
8589
stubtest_dependencies: list[str]
8690
mypy_plugins: list[str]
8791
mypy_plugins_config: dict[str, dict[str, Any]]
92+
install_environment: dict[str, str]
8893

8994
def system_requirements_for_platform(self, platform: str) -> list[str]:
9095
assert platform in _STUBTEST_PLATFORM_MAPPING, f"Unrecognised platform {platform!r}"
@@ -110,6 +115,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
110115
stubtest_dependencies: object = data.get("stubtest-dependencies", [])
111116
mypy_plugins: object = data.get("mypy-plugins", [])
112117
mypy_plugins_config: object = data.get("mypy-plugins-config", {})
118+
install_environment: object = data.get("install-environment", {})
113119

114120
assert type(skip) is bool
115121
assert type(ignore_missing_stub) is bool
@@ -124,6 +130,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
124130
assert _is_list_of_strings(stubtest_dependencies)
125131
assert _is_list_of_strings(mypy_plugins)
126132
assert _is_nested_dict(mypy_plugins_config)
133+
assert _is_dict_of_strings(install_environment)
127134

128135
unrecognised_platforms = set(ci_platforms) - _STUBTEST_PLATFORM_MAPPING.keys()
129136
assert not unrecognised_platforms, f"Unrecognised ci-platforms specified for {distribution!r}: {unrecognised_platforms}"
@@ -152,6 +159,7 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
152159
stubtest_dependencies=stubtest_dependencies,
153160
mypy_plugins=mypy_plugins,
154161
mypy_plugins_config=mypy_plugins_config,
162+
install_environment=install_environment,
155163
)
156164

157165

@@ -227,6 +235,7 @@ def all_dependencies(self) -> list[Requirement]:
227235
"stubtest-dependencies",
228236
"mypy-plugins",
229237
"mypy-plugins-config",
238+
"install-environment",
230239
}
231240
}
232241
_DIST_NAME_RE: Final = re.compile(r"^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$", re.IGNORECASE)

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ _ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed
157157
_frozen_importlib_external.ExtensionFileLoader.get_filename
158158
_frozen_importlib_external.FileLoader.get_filename
159159
_frozen_importlib_external.FileLoader.get_resource_reader
160-
_frozen_importlib_external.FileLoader.load_module
161160

162161
# Mismatch of default values of `report` parameter:
163162
_markupbase.ParserBase.parse_comment
@@ -277,7 +276,6 @@ importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined
277276

278277
# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
279278
importlib.abc.FileLoader.get_filename
280-
importlib.abc.FileLoader.load_module
281279

282280
importlib.metadata._meta.SimplePath.joinpath # Runtime definition of protocol is incorrect
283281

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ typing(_extensions)?\.IO\.writelines
162162
posixpath.join
163163
ntpath.join
164164

165+
# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
166+
_frozen_importlib_external.FileLoader.load_module
167+
importlib.abc.FileLoader.load_module
168+
165169

166170
# ===============================================================
167171
# Allowlist entries that cannot or should not be fixed; 3.10 only

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ typing(_extensions)?\.IO\.writelines
140140
posixpath.join
141141
ntpath.join
142142

143+
# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
144+
_frozen_importlib_external.FileLoader.load_module
145+
importlib.abc.FileLoader.load_module
146+
143147

144148
# =============================================================
145149
# Allowlist entries that cannot or should not be fixed; >= 3.11

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ typing(_extensions)?\.IO\.writelines
133133
posixpath.join
134134
ntpath.join
135135

136+
# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
137+
_frozen_importlib_external.FileLoader.load_module
138+
importlib.abc.FileLoader.load_module
139+
136140

137141
# =============================================================
138142
# Allowlist entries that cannot or should not be fixed; >= 3.12

stdlib/@tests/stubtest_allowlists/py313.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ typing(_extensions)?\.IO\.writelines
9191
posixpath.join
9292
ntpath.join
9393

94+
# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
95+
_frozen_importlib_external.FileLoader.load_module
96+
importlib.abc.FileLoader.load_module
97+
9498

9599
# =============================================================
96100
# Allowlist entries that cannot or should not be fixed; >= 3.13

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ concurrent.interpreters._crossinterp.UNBOUND_REMOVE
2424
# Condition functions are exported in __init__
2525
threading.Condition.locked
2626

27-
# Starting with Python 3.14.1, these methods accept None for some of their
28-
# parameters, but would raise a TypeError with Python 3.14.0.
29-
mmap.mmap.find
30-
mmap.mmap.flush
31-
mmap.mmap.rfind
32-
multiprocessing.process.BaseProcess.__init__
33-
3427
# ====================================
3528
# Pre-existing errors from Python 3.13
3629
# ====================================
@@ -91,6 +84,10 @@ typing(_extensions)?\.IO\.writelines
9184
posixpath.join
9285
ntpath.join
9386

87+
# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
88+
_frozen_importlib_external.FileLoader.load_module
89+
importlib.abc.FileLoader.load_module
90+
9491

9592
# =============================================================
9693
# Allowlist entries that cannot or should not be fixed; >= 3.14

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,13 @@
22
# TODO: Allowlist entries that should be fixed
33
# ============================================
44

5-
_frozen_importlib.BuiltinImporter.load_module
6-
_frozen_importlib.FrozenImporter.load_module
7-
_frozen_importlib_external.FileFinder.discover
8-
_frozen_importlib_external.NamespaceLoader.load_module
9-
_frozen_importlib_external.NamespacePath
105
_frozen_importlib_external.PathFinder.discover
116
_frozen_importlib_external.SourceFileLoader.source_to_code
127
_frozen_importlib_external.SourceLoader.source_to_code
13-
_frozen_importlib_external._LoaderBasics.load_module
14-
_frozen_importlib_external.cache_from_source
15-
_struct.Struct.pack_into
16-
_struct.pack
17-
_struct.pack_into
18-
_thread.RLock.__exit__
19-
_thread.lock.__exit__
208
dataclasses.MISSING
219
dataclasses._MISSING_TYPE
2210
dataclasses.field
23-
importlib._abc.Loader.load_module
24-
importlib._bootstrap_external.NamespacePath
25-
importlib.abc.MetaPathFinder.discover
26-
importlib.abc.PathEntryFinder.discover
27-
importlib.resources._common.package_to_anchor
2811
mailbox._ProxyFile.__class_getitem__
29-
multiprocessing.process.BaseProcess.__init__
30-
threading.Condition.locked
3112

3213
# =============================================================
3314
# Allowlist entries that cannot or should not be fixed; >= 3.15
@@ -90,6 +71,9 @@ concurrent.interpreters._crossinterp.UnboundItem.singleton
9071
concurrent.interpreters._crossinterp.UNBOUND_ERROR
9172
concurrent.interpreters._crossinterp.UNBOUND_REMOVE
9273

74+
# Condition functions are exported in __init__
75+
threading.Condition.locked
76+
9377
# Assigning `__new__` causes `func` not to get recognized.
9478
functools.partialmethod.__new__
9579

@@ -151,9 +135,6 @@ typing_extensions.Protocol # Super-special typing primitive
151135
# Allowlist entries that cannot or should not be fixed; >= 3.12
152136
# =============================================================
153137

154-
# Deprecated argument is supported at runtime by renaming it through a decorator.
155-
importlib.resources._common.files
156-
157138
sys._monitoring # Doesn't really exist. See comments in the stub.
158139
sys.__jit # Similar to sys._monitoring
159140
sys.last_exc # Not always defined.

stdlib/@tests/test_cases/check_inspect.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import annotations
22

33
import inspect
4-
from collections.abc import Awaitable, Callable, Coroutine
5-
from types import CoroutineType
4+
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator
65
from typing import Any
76
from typing_extensions import assert_type
87

@@ -17,10 +16,24 @@ def test_iscoroutinefunction_inspect(
1716
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])
1817

1918
if inspect.iscoroutinefunction(y):
20-
assert_type(y, Callable[[str, int], CoroutineType[Any, Any, bytes]])
19+
assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]])
2120

2221
if inspect.iscoroutinefunction(z):
23-
assert_type(z, Callable[[str, int], CoroutineType[Any, Any, Any]])
22+
assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]])
2423

2524
if inspect.iscoroutinefunction(xx):
26-
assert_type(xx, Callable[..., CoroutineType[Any, Any, Any]])
25+
assert_type(xx, Callable[..., Coroutine[Any, Any, Any]])
26+
27+
28+
def test_isgeneratorfunction_inspect(x: Callable[[str], object], y: object) -> None:
29+
if inspect.isgeneratorfunction(x):
30+
assert_type(x, Callable[[str], Generator[Any, Any, Any]])
31+
if inspect.isgeneratorfunction(y):
32+
assert_type(y, Callable[..., Generator[Any, Any, Any]])
33+
34+
35+
def test_isasyncgenfunction_inspect(x: Callable[[str], object], y: object) -> None:
36+
if inspect.isasyncgenfunction(x):
37+
assert_type(x, Callable[[str], AsyncGenerator[Any, Any]])
38+
if inspect.isasyncgenfunction(y):
39+
assert_type(y, Callable[..., AsyncGenerator[Any, Any]])

0 commit comments

Comments
 (0)