Skip to content

Commit 0d91a80

Browse files
committed
Address builtins PR review feedback
1 parent bd39c02 commit 0d91a80

4 files changed

Lines changed: 117 additions & 74 deletions

File tree

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ binascii.b2a_base32
118118
binascii.b2a_base64
119119
binascii.b2a_base85
120120
binascii.unhexlify
121-
builtins.compile
122121
cProfile.label
123122
calendar.HTMLCalendar.formatmonthpage
124123
calendar.__all__
@@ -147,6 +146,8 @@ concurrent.interpreters._crossinterp.classonly.__wrapped__
147146
copy.deepcopy
148147
ctypes.SetPointerType
149148
dataclasses._MISSING_TYPE
149+
dataclasses.MISSING
150+
dataclasses.field
150151
datetime.date.fromisoformat
151152
datetime.date.strptime
152153
datetime.datetime.fromisoformat

stdlib/builtins.pyi

Lines changed: 95 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,49 +1472,99 @@ async def anext(i: SupportsAnext[_T], default: _VT, /) -> _T | _VT: ...
14721472
# compile() returns a CodeType, unless the flags argument includes PyCF_ONLY_AST (=1024),
14731473
# in which case it returns ast.AST. We have overloads for flag 0 (the default) and for
14741474
# explicitly passing PyCF_ONLY_AST. We fall back to Any for other values of flags.
1475-
@overload
1476-
def compile(
1477-
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1478-
filename: str | bytes | PathLike[Any],
1479-
mode: str,
1480-
flags: Literal[0],
1481-
dont_inherit: bool = False,
1482-
optimize: int = -1,
1483-
*,
1484-
_feature_version: int = -1,
1485-
) -> CodeType: ...
1486-
@overload
1487-
def compile(
1488-
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1489-
filename: str | bytes | PathLike[Any],
1490-
mode: str,
1491-
*,
1492-
dont_inherit: bool = False,
1493-
optimize: int = -1,
1494-
_feature_version: int = -1,
1495-
) -> CodeType: ...
1496-
@overload
1497-
def compile(
1498-
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1499-
filename: str | bytes | PathLike[Any],
1500-
mode: str,
1501-
flags: Literal[1024],
1502-
dont_inherit: bool = False,
1503-
optimize: int = -1,
1504-
*,
1505-
_feature_version: int = -1,
1506-
) -> _ast.AST: ...
1507-
@overload
1508-
def compile(
1509-
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1510-
filename: str | bytes | PathLike[Any],
1511-
mode: str,
1512-
flags: int,
1513-
dont_inherit: bool = False,
1514-
optimize: int = -1,
1515-
*,
1516-
_feature_version: int = -1,
1517-
) -> Any: ...
1475+
if sys.version_info >= (3, 15):
1476+
@overload
1477+
def compile(
1478+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1479+
filename: str | bytes | PathLike[Any],
1480+
mode: str,
1481+
flags: Literal[0],
1482+
dont_inherit: bool = False,
1483+
optimize: int = -1,
1484+
*,
1485+
module: str | None = None,
1486+
_feature_version: int = -1,
1487+
) -> CodeType: ...
1488+
@overload
1489+
def compile(
1490+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1491+
filename: str | bytes | PathLike[Any],
1492+
mode: str,
1493+
*,
1494+
dont_inherit: bool = False,
1495+
optimize: int = -1,
1496+
module: str | None = None,
1497+
_feature_version: int = -1,
1498+
) -> CodeType: ...
1499+
@overload
1500+
def compile(
1501+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1502+
filename: str | bytes | PathLike[Any],
1503+
mode: str,
1504+
flags: Literal[1024],
1505+
dont_inherit: bool = False,
1506+
optimize: int = -1,
1507+
*,
1508+
module: str | None = None,
1509+
_feature_version: int = -1,
1510+
) -> _ast.AST: ...
1511+
@overload
1512+
def compile(
1513+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1514+
filename: str | bytes | PathLike[Any],
1515+
mode: str,
1516+
flags: int,
1517+
dont_inherit: bool = False,
1518+
optimize: int = -1,
1519+
*,
1520+
module: str | None = None,
1521+
_feature_version: int = -1,
1522+
) -> Any: ...
1523+
1524+
else:
1525+
@overload
1526+
def compile(
1527+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1528+
filename: str | bytes | PathLike[Any],
1529+
mode: str,
1530+
flags: Literal[0],
1531+
dont_inherit: bool = False,
1532+
optimize: int = -1,
1533+
*,
1534+
_feature_version: int = -1,
1535+
) -> CodeType: ...
1536+
@overload
1537+
def compile(
1538+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1539+
filename: str | bytes | PathLike[Any],
1540+
mode: str,
1541+
*,
1542+
dont_inherit: bool = False,
1543+
optimize: int = -1,
1544+
_feature_version: int = -1,
1545+
) -> CodeType: ...
1546+
@overload
1547+
def compile(
1548+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1549+
filename: str | bytes | PathLike[Any],
1550+
mode: str,
1551+
flags: Literal[1024],
1552+
dont_inherit: bool = False,
1553+
optimize: int = -1,
1554+
*,
1555+
_feature_version: int = -1,
1556+
) -> _ast.AST: ...
1557+
@overload
1558+
def compile(
1559+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
1560+
filename: str | bytes | PathLike[Any],
1561+
mode: str,
1562+
flags: int,
1563+
dont_inherit: bool = False,
1564+
optimize: int = -1,
1565+
*,
1566+
_feature_version: int = -1,
1567+
) -> Any: ...
15181568

15191569
copyright: _sitebuiltins._Printer
15201570
credits: _sitebuiltins._Printer
@@ -2012,8 +2062,8 @@ if sys.version_info >= (3, 15):
20122062
def __new__(cls, name: str, /) -> Self: ...
20132063
def __copy__(self, /) -> Self: ...
20142064
def __deepcopy__(self, memo: Any, /) -> Self: ...
2015-
def __or__(self, other: Any, /) -> types.UnionType: ...
2016-
def __ror__(self, other: Any, /) -> types.UnionType: ...
2065+
def __or__(self, other: Any, /) -> Any: ...
2066+
def __ror__(self, other: Any, /) -> Any: ...
20172067

20182068
@overload
20192069
def sorted(

stdlib/collections/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, fin
1818
from typing_extensions import Self, disjoint_base
1919

2020
if sys.version_info >= (3, 15):
21-
from builtins import frozendict as frozendict
21+
from builtins import frozendict
2222

2323
__all__ = ["ChainMap", "Counter", "OrderedDict", "UserDict", "UserList", "UserString", "defaultdict", "deque", "namedtuple"]
2424

stdlib/dataclasses.pyi

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ 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, TypeAlias, TypeVar, overload, type_check_only
8+
from typing import Any, Final, Generic, Literal, Protocol, 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-
1411
_T = TypeVar("_T")
1512
_T_co = TypeVar("_T_co", covariant=True)
1613

@@ -59,12 +56,7 @@ class _DataclassFactory(Protocol):
5956
class _MISSING_TYPE(enum.Enum):
6057
MISSING = enum.auto()
6158

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

6961
class KW_ONLY: ...
7062

@@ -180,8 +172,8 @@ class Field(Generic[_T]):
180172
)
181173
name: str
182174
type: Type[_T] | str | Any
183-
default: _T | _MISSING
184-
default_factory: _DefaultFactory[_T] | _MISSING
175+
default: _T | Literal[_MISSING_TYPE.MISSING]
176+
default_factory: _DefaultFactory[_T] | Literal[_MISSING_TYPE.MISSING]
185177
repr: bool
186178
hash: bool | None
187179
init: bool
@@ -191,7 +183,7 @@ class Field(Generic[_T]):
191183
if sys.version_info >= (3, 14):
192184
doc: str | None
193185

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

196188
if sys.version_info >= (3, 14):
197189
def __init__(
@@ -229,39 +221,39 @@ if sys.version_info >= (3, 14):
229221
def field(
230222
*,
231223
default: _T,
232-
default_factory: _MISSING = ...,
224+
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
233225
init: bool = True,
234226
repr: bool = True,
235227
hash: bool | None = None,
236228
compare: bool = True,
237229
metadata: Mapping[Any, Any] | None = None,
238-
kw_only: bool | _MISSING = ...,
230+
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
239231
doc: str | None = None,
240232
) -> _T: ...
241233
@overload
242234
def field(
243235
*,
244-
default: _MISSING = ...,
236+
default: Literal[_MISSING_TYPE.MISSING] = ...,
245237
default_factory: Callable[[], _T],
246238
init: bool = True,
247239
repr: bool = True,
248240
hash: bool | None = None,
249241
compare: bool = True,
250242
metadata: Mapping[Any, Any] | None = None,
251-
kw_only: bool | _MISSING = ...,
243+
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
252244
doc: str | None = None,
253245
) -> _T: ...
254246
@overload
255247
def field(
256248
*,
257-
default: _MISSING = ...,
258-
default_factory: _MISSING = ...,
249+
default: Literal[_MISSING_TYPE.MISSING] = ...,
250+
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
259251
init: bool = True,
260252
repr: bool = True,
261253
hash: bool | None = None,
262254
compare: bool = True,
263255
metadata: Mapping[Any, Any] | None = None,
264-
kw_only: bool | _MISSING = ...,
256+
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
265257
doc: str | None = None,
266258
) -> Any: ...
267259

@@ -270,37 +262,37 @@ else:
270262
def field(
271263
*,
272264
default: _T,
273-
default_factory: _MISSING = ...,
265+
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
274266
init: bool = True,
275267
repr: bool = True,
276268
hash: bool | None = None,
277269
compare: bool = True,
278270
metadata: Mapping[Any, Any] | None = None,
279-
kw_only: bool | _MISSING = ...,
271+
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
280272
) -> _T: ...
281273
@overload
282274
def field(
283275
*,
284-
default: _MISSING = ...,
276+
default: Literal[_MISSING_TYPE.MISSING] = ...,
285277
default_factory: Callable[[], _T],
286278
init: bool = True,
287279
repr: bool = True,
288280
hash: bool | None = None,
289281
compare: bool = True,
290282
metadata: Mapping[Any, Any] | None = None,
291-
kw_only: bool | _MISSING = ...,
283+
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
292284
) -> _T: ...
293285
@overload
294286
def field(
295287
*,
296-
default: _MISSING = ...,
297-
default_factory: _MISSING = ...,
288+
default: Literal[_MISSING_TYPE.MISSING] = ...,
289+
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
298290
init: bool = True,
299291
repr: bool = True,
300292
hash: bool | None = None,
301293
compare: bool = True,
302294
metadata: Mapping[Any, Any] | None = None,
303-
kw_only: bool | _MISSING = ...,
295+
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
304296
) -> Any: ...
305297

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

0 commit comments

Comments
 (0)