Skip to content

Commit 349a955

Browse files
committed
Handle Python 3.15 sentinel and frozendict fallout
1 parent b7388f8 commit 349a955

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

stdlib/dataclasses.pyi

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ from _typeshed import DataclassInstance
55
from builtins import type as Type # alias to avoid name clashes with fields named "type"
66
from collections.abc import Callable, Iterable, Mapping
77
from types import GenericAlias
8-
from typing import Any, Final, Generic, Literal, Protocol, TypeVar, overload, type_check_only
8+
from typing import Any, Final, Generic, Literal, Protocol, TypeAlias, TypeVar, overload, type_check_only
99
from typing_extensions import Never, TypeIs
1010

11+
if sys.version_info >= (3, 15):
12+
from builtins import sentinel as _sentinel
13+
1114
_T = TypeVar("_T")
1215
_T_co = TypeVar("_T_co", covariant=True)
1316

@@ -56,7 +59,12 @@ class _DataclassFactory(Protocol):
5659
class _MISSING_TYPE(enum.Enum):
5760
MISSING = enum.auto()
5861

59-
MISSING: Final = _MISSING_TYPE.MISSING
62+
if sys.version_info >= (3, 15):
63+
_MISSING: TypeAlias = _sentinel
64+
else:
65+
_MISSING: TypeAlias = Literal[_MISSING_TYPE.MISSING]
66+
67+
MISSING: Final[_MISSING]
6068

6169
class KW_ONLY: ...
6270

@@ -172,8 +180,8 @@ class Field(Generic[_T]):
172180
)
173181
name: str
174182
type: Type[_T] | str | Any
175-
default: _T | Literal[_MISSING_TYPE.MISSING]
176-
default_factory: _DefaultFactory[_T] | Literal[_MISSING_TYPE.MISSING]
183+
default: _T | _MISSING
184+
default_factory: _DefaultFactory[_T] | _MISSING
177185
repr: bool
178186
hash: bool | None
179187
init: bool
@@ -183,7 +191,7 @@ class Field(Generic[_T]):
183191
if sys.version_info >= (3, 14):
184192
doc: str | None
185193

186-
kw_only: bool | Literal[_MISSING_TYPE.MISSING]
194+
kw_only: bool | _MISSING
187195

188196
if sys.version_info >= (3, 14):
189197
def __init__(
@@ -221,39 +229,39 @@ if sys.version_info >= (3, 14):
221229
def field(
222230
*,
223231
default: _T,
224-
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
232+
default_factory: _MISSING = ...,
225233
init: bool = True,
226234
repr: bool = True,
227235
hash: bool | None = None,
228236
compare: bool = True,
229237
metadata: Mapping[Any, Any] | None = None,
230-
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
238+
kw_only: bool | _MISSING = ...,
231239
doc: str | None = None,
232240
) -> _T: ...
233241
@overload
234242
def field(
235243
*,
236-
default: Literal[_MISSING_TYPE.MISSING] = ...,
244+
default: _MISSING = ...,
237245
default_factory: Callable[[], _T],
238246
init: bool = True,
239247
repr: bool = True,
240248
hash: bool | None = None,
241249
compare: bool = True,
242250
metadata: Mapping[Any, Any] | None = None,
243-
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
251+
kw_only: bool | _MISSING = ...,
244252
doc: str | None = None,
245253
) -> _T: ...
246254
@overload
247255
def field(
248256
*,
249-
default: Literal[_MISSING_TYPE.MISSING] = ...,
250-
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
257+
default: _MISSING = ...,
258+
default_factory: _MISSING = ...,
251259
init: bool = True,
252260
repr: bool = True,
253261
hash: bool | None = None,
254262
compare: bool = True,
255263
metadata: Mapping[Any, Any] | None = None,
256-
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
264+
kw_only: bool | _MISSING = ...,
257265
doc: str | None = None,
258266
) -> Any: ...
259267

@@ -262,37 +270,37 @@ else:
262270
def field(
263271
*,
264272
default: _T,
265-
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
273+
default_factory: _MISSING = ...,
266274
init: bool = True,
267275
repr: bool = True,
268276
hash: bool | None = None,
269277
compare: bool = True,
270278
metadata: Mapping[Any, Any] | None = None,
271-
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
279+
kw_only: bool | _MISSING = ...,
272280
) -> _T: ...
273281
@overload
274282
def field(
275283
*,
276-
default: Literal[_MISSING_TYPE.MISSING] = ...,
284+
default: _MISSING = ...,
277285
default_factory: Callable[[], _T],
278286
init: bool = True,
279287
repr: bool = True,
280288
hash: bool | None = None,
281289
compare: bool = True,
282290
metadata: Mapping[Any, Any] | None = None,
283-
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
291+
kw_only: bool | _MISSING = ...,
284292
) -> _T: ...
285293
@overload
286294
def field(
287295
*,
288-
default: Literal[_MISSING_TYPE.MISSING] = ...,
289-
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
296+
default: _MISSING = ...,
297+
default_factory: _MISSING = ...,
290298
init: bool = True,
291299
repr: bool = True,
292300
hash: bool | None = None,
293301
compare: bool = True,
294302
metadata: Mapping[Any, Any] | None = None,
295-
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
303+
kw_only: bool | _MISSING = ...,
296304
) -> Any: ...
297305

298306
def fields(class_or_instance: DataclassInstance | type[DataclassInstance]) -> tuple[Field[Any], ...]: ...

stdlib/opcode.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import sys
22
from typing import Final, Literal
33

4+
if sys.version_info >= (3, 15):
5+
from builtins import frozendict
6+
47
__all__ = [
58
"cmp_op",
69
"hasconst",
@@ -40,7 +43,10 @@ if sys.version_info >= (3, 13):
4043
hasjump: Final[list[int]]
4144
opname: Final[list[str]]
4245

43-
opmap: Final[dict[str, int]]
46+
if sys.version_info >= (3, 15):
47+
opmap: Final[frozendict[str, int]]
48+
else:
49+
opmap: Final[dict[str, int]]
4450
HAVE_ARGUMENT: Final[int]
4551
EXTENDED_ARG: Final[int]
4652

0 commit comments

Comments
 (0)