Skip to content

Commit 551313d

Browse files
Add Python 3.15 argparse ast and runtime updates (#15736)
1 parent 8bb4b55 commit 551313d

12 files changed

Lines changed: 425 additions & 101 deletions

File tree

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ annotationlib.ForwardRef.__resolved_str__
6060
annotationlib.ForwardRef.__resolved_str_cache__
6161
annotationlib.ForwardRef.__slots__
6262
annotationlib.ForwardRef.__stringifier_dict__
63-
argparse.ArgumentParser.__init__
64-
argparse.ArgumentParser._get_formatter
65-
argparse.ArgumentParser.format_help
66-
argparse.ArgumentParser.format_usage
67-
argparse.HelpFormatter.__init__
68-
array.typecodes
69-
ast.DictComp.value
70-
ast.Import.__match_args__
71-
ast.Import.is_lazy
72-
ast.ImportFrom.__match_args__
73-
ast.ImportFrom.is_lazy
74-
ast.dump
75-
ast.parse
7663
ast.type_param.__init__
7764
# base64.b64decode uses a private sentinel list as the default for parameters whose public types are bool/buffer.
7865
base64.b64decode
@@ -225,16 +212,6 @@ profiling.sampling.string_table
225212
profiling.tracing
226213
pydoc.Doc.STDLIB_DIR
227214
pydoc.Doc.getdocloc
228-
re.Pattern.prefixmatch
229-
re.__all__
230-
re.prefixmatch
231-
shelve.BsdDbShelf.__init__
232-
shelve.DbfilenameShelf.__init__
233-
shelve.Shelf.__init__
234-
shelve.Shelf.reorganize
235-
shelve.ShelveError
236-
shelve.__all__
237-
shelve.open
238215
site.addsitedir
239216
site.addsitepackages
240217
site.addusersitepackages
@@ -258,7 +235,6 @@ sys.last_exc
258235
sys.lazy_modules
259236
sys.set_lazy_imports
260237
sys.set_lazy_imports_filter
261-
tarfile.TarFile.__init__
262238
threading.Condition.locked
263239
threading.__all__
264240
threading.concurrent_tee
@@ -308,8 +284,6 @@ typing.Union
308284
typing._SpecialForm.__mro_entries__
309285
typing_extensions.__all__
310286
typing_extensions.Protocol
311-
unittest._log._AssertLogsContext.__init__
312-
unittest.case.TestCase.assertLogs
313287
urllib.parse._DefragResultBase.geturl
314288
urllib.parse._ParseResultBase.geturl
315289
urllib.parse._SplitResultBase.geturl
@@ -318,18 +292,6 @@ urllib.parse.urlparse
318292
urllib.parse.urlsplit
319293
urllib.parse.urlunparse
320294
urllib.parse.urlunsplit
321-
warnings.WarningMessage.__init__
322-
wave.WAVE_FORMAT_EXTENSIBLE
323-
wave.WAVE_FORMAT_IEEE_FLOAT
324-
wave.Wave_read.getformat
325-
wave.Wave_read.getmark
326-
wave.Wave_read.getmarkers
327-
wave.Wave_write.getformat
328-
wave.Wave_write.getmark
329-
wave.Wave_write.getmarkers
330-
wave.Wave_write.setformat
331-
wave.Wave_write.setmark
332-
wave.__all__
333295
xml.etree.ElementTree.__all__
334296
xml.is_valid_name
335297
xml.utils

stdlib/argparse.pyi

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,28 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
161161
_subparsers: _ArgumentGroup | None
162162

163163
# Note: the constructor arguments are also used in _SubParsersAction.add_parser.
164-
if sys.version_info >= (3, 14):
164+
if sys.version_info >= (3, 15):
165+
def __init__(
166+
self,
167+
prog: str | None = None,
168+
usage: str | None = None,
169+
description: str | None = None,
170+
epilog: str | None = None,
171+
parents: Iterable[ArgumentParser] = [],
172+
formatter_class: _FormatterClass = ...,
173+
prefix_chars: str = "-",
174+
fromfile_prefix_chars: str | None = None,
175+
argument_default: Any = None,
176+
conflict_handler: str = "error",
177+
add_help: bool = True,
178+
allow_abbrev: bool = True,
179+
exit_on_error: bool = True,
180+
*,
181+
suggest_on_error: bool = True,
182+
color: bool = True,
183+
) -> None: ...
184+
185+
elif sys.version_info >= (3, 14):
165186
def __init__(
166187
self,
167188
prog: str | None = None,
@@ -236,8 +257,14 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
236257
) -> _SubParsersAction[_ArgumentParserT]: ...
237258
def print_usage(self, file: SupportsWrite[str] | None = None) -> None: ...
238259
def print_help(self, file: SupportsWrite[str] | None = None) -> None: ...
239-
def format_usage(self) -> str: ...
240-
def format_help(self) -> str: ...
260+
if sys.version_info >= (3, 15):
261+
def format_usage(self, formatter: HelpFormatter | None = None) -> str: ...
262+
def format_help(self, formatter: HelpFormatter | None = None) -> str: ...
263+
264+
else:
265+
def format_usage(self) -> str: ...
266+
def format_help(self) -> str: ...
267+
241268
@overload
242269
def parse_known_args(self, args: Iterable[str] | None = None, namespace: None = None) -> tuple[Namespace, list[str]]: ...
243270
@overload
@@ -284,7 +311,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
284311
def _get_values(self, action: Action, arg_strings: list[str]) -> Any: ...
285312
def _get_value(self, action: Action, arg_string: str) -> Any: ...
286313
def _check_value(self, action: Action, value: Any) -> None: ...
287-
def _get_formatter(self) -> HelpFormatter: ...
314+
if sys.version_info >= (3, 15):
315+
def _get_formatter(self, file: SupportsWrite[str] | None = None) -> HelpFormatter: ...
316+
else:
317+
def _get_formatter(self) -> HelpFormatter: ...
318+
288319
def _print_message(self, message: str, file: SupportsWrite[str] | None = None) -> None: ...
289320

290321
class HelpFormatter:
@@ -309,7 +340,12 @@ class HelpFormatter:
309340
def __init__(self, formatter: HelpFormatter, parent: Self | None, heading: str | None = None) -> None: ...
310341
def format_help(self) -> str: ...
311342

312-
if sys.version_info >= (3, 14):
343+
if sys.version_info >= (3, 15):
344+
def __init__(
345+
self, prog: str, indent_increment: int = 2, max_help_position: int = 24, width: int | None = None
346+
) -> None: ...
347+
348+
elif sys.version_info >= (3, 14):
313349
def __init__(
314350
self, prog: str, indent_increment: int = 2, max_help_position: int = 24, width: int | None = None, color: bool = True
315351
) -> None: ...

stdlib/array.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ from typing import Any, ClassVar, Literal, SupportsIndex, TypeAlias, TypeVar, ov
66
from typing_extensions import Self, deprecated, disjoint_base
77

88
_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
9-
_FloatTypeCode: TypeAlias = Literal["f", "d"]
9+
if sys.version_info >= (3, 15):
10+
_FloatTypeCode: TypeAlias = Literal["f", "d", "e", "Zf", "Zd"]
11+
else:
12+
_FloatTypeCode: TypeAlias = Literal["f", "d"]
1013
if sys.version_info >= (3, 13):
1114
_UnicodeTypeCode: TypeAlias = Literal["u", "w"]
1215
else:
@@ -15,7 +18,10 @@ _TypeCode: TypeAlias = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode
1518

1619
_T = TypeVar("_T", int, float, str)
1720

18-
typecodes: str
21+
if sys.version_info >= (3, 15):
22+
typecodes: tuple[str, ...]
23+
else:
24+
typecodes: str
1925

2026
@disjoint_base
2127
class array(MutableSequence[_T]):

stdlib/ast.pyi

Lines changed: 164 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -710,22 +710,54 @@ class Assert(stmt):
710710
def __replace__(self, *, test: expr = ..., msg: expr | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
711711

712712
class Import(stmt):
713-
__match_args__ = ("names",)
713+
if sys.version_info >= (3, 15):
714+
__match_args__ = ("names", "is_lazy")
715+
else:
716+
__match_args__ = ("names",)
714717
names: list[alias]
715-
if sys.version_info >= (3, 13):
718+
if sys.version_info >= (3, 15):
719+
is_lazy: bool | None
720+
if sys.version_info >= (3, 15):
721+
def __init__(self, names: list[alias] = ..., is_lazy: bool | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
722+
723+
elif sys.version_info >= (3, 13):
716724
def __init__(self, names: list[alias] = ..., **kwargs: Unpack[_Attributes]) -> None: ...
717725
else:
718726
def __init__(self, names: list[alias], **kwargs: Unpack[_Attributes]) -> None: ...
719727

720-
if sys.version_info >= (3, 14):
728+
if sys.version_info >= (3, 15):
729+
def __replace__(self, *, names: list[alias] = ..., is_lazy: bool | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
730+
731+
elif sys.version_info >= (3, 14):
721732
def __replace__(self, *, names: list[alias] = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
722733

723734
class ImportFrom(stmt):
724-
__match_args__ = ("module", "names", "level")
735+
if sys.version_info >= (3, 15):
736+
__match_args__ = ("module", "names", "level", "is_lazy")
737+
else:
738+
__match_args__ = ("module", "names", "level")
725739
module: str | None
726740
names: list[alias]
727741
level: int
728-
if sys.version_info >= (3, 13):
742+
if sys.version_info >= (3, 15):
743+
is_lazy: bool | None
744+
if sys.version_info >= (3, 15):
745+
@overload
746+
def __init__(
747+
self, module: str | None, names: list[alias], level: int, is_lazy: bool | None = None, **kwargs: Unpack[_Attributes]
748+
) -> None: ...
749+
@overload
750+
def __init__(
751+
self,
752+
module: str | None = None,
753+
names: list[alias] = ...,
754+
*,
755+
level: int,
756+
is_lazy: bool | None = None,
757+
**kwargs: Unpack[_Attributes],
758+
) -> None: ...
759+
760+
elif sys.version_info >= (3, 13):
729761
@overload
730762
def __init__(self, module: str | None, names: list[alias], level: int, **kwargs: Unpack[_Attributes]) -> None: ...
731763
@overload
@@ -740,7 +772,18 @@ class ImportFrom(stmt):
740772
self, module: str | None = None, *, names: list[alias], level: int, **kwargs: Unpack[_Attributes]
741773
) -> None: ...
742774

743-
if sys.version_info >= (3, 14):
775+
if sys.version_info >= (3, 15):
776+
def __replace__(
777+
self,
778+
*,
779+
module: str | None = ...,
780+
names: list[alias] = ...,
781+
level: int = ...,
782+
is_lazy: bool | None = ...,
783+
**kwargs: Unpack[_Attributes],
784+
) -> Self: ...
785+
786+
elif sys.version_info >= (3, 14):
744787
def __replace__(
745788
self, *, module: str | None = ..., names: list[alias] = ..., level: int = ..., **kwargs: Unpack[_Attributes]
746789
) -> Self: ...
@@ -908,7 +951,10 @@ class SetComp(expr):
908951
class DictComp(expr):
909952
__match_args__ = ("key", "value", "generators")
910953
key: expr
911-
value: expr
954+
if sys.version_info >= (3, 15):
955+
value: expr | None
956+
else:
957+
value: expr
912958
generators: list[comprehension]
913959
if sys.version_info >= (3, 13):
914960
def __init__(
@@ -1672,7 +1718,105 @@ if sys.version_info < (3, 14):
16721718

16731719
_T = _TypeVar("_T", bound=AST)
16741720

1675-
if sys.version_info >= (3, 13):
1721+
if sys.version_info >= (3, 15):
1722+
@overload
1723+
def parse(
1724+
source: _T,
1725+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
1726+
mode: Literal["exec", "eval", "func_type", "single"] = "exec",
1727+
*,
1728+
type_comments: bool = False,
1729+
feature_version: None | int | tuple[int, int] = None,
1730+
optimize: Literal[-1, 0, 1, 2] = -1,
1731+
module: str | None = None,
1732+
) -> _T: ...
1733+
@overload
1734+
def parse(
1735+
source: str | ReadableBuffer,
1736+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
1737+
mode: Literal["exec"] = "exec",
1738+
*,
1739+
type_comments: bool = False,
1740+
feature_version: None | int | tuple[int, int] = None,
1741+
optimize: Literal[-1, 0, 1, 2] = -1,
1742+
module: str | None = None,
1743+
) -> Module: ...
1744+
@overload
1745+
def parse(
1746+
source: str | ReadableBuffer,
1747+
filename: str | bytes | os.PathLike[Any],
1748+
mode: Literal["eval"],
1749+
*,
1750+
type_comments: bool = False,
1751+
feature_version: None | int | tuple[int, int] = None,
1752+
optimize: Literal[-1, 0, 1, 2] = -1,
1753+
module: str | None = None,
1754+
) -> Expression: ...
1755+
@overload
1756+
def parse(
1757+
source: str | ReadableBuffer,
1758+
filename: str | bytes | os.PathLike[Any],
1759+
mode: Literal["func_type"],
1760+
*,
1761+
type_comments: bool = False,
1762+
feature_version: None | int | tuple[int, int] = None,
1763+
optimize: Literal[-1, 0, 1, 2] = -1,
1764+
module: str | None = None,
1765+
) -> FunctionType: ...
1766+
@overload
1767+
def parse(
1768+
source: str | ReadableBuffer,
1769+
filename: str | bytes | os.PathLike[Any],
1770+
mode: Literal["single"],
1771+
*,
1772+
type_comments: bool = False,
1773+
feature_version: None | int | tuple[int, int] = None,
1774+
optimize: Literal[-1, 0, 1, 2] = -1,
1775+
module: str | None = None,
1776+
) -> Interactive: ...
1777+
@overload
1778+
def parse(
1779+
source: str | ReadableBuffer,
1780+
*,
1781+
mode: Literal["eval"],
1782+
type_comments: bool = False,
1783+
feature_version: None | int | tuple[int, int] = None,
1784+
optimize: Literal[-1, 0, 1, 2] = -1,
1785+
module: str | None = None,
1786+
) -> Expression: ...
1787+
@overload
1788+
def parse(
1789+
source: str | ReadableBuffer,
1790+
*,
1791+
mode: Literal["func_type"],
1792+
type_comments: bool = False,
1793+
feature_version: None | int | tuple[int, int] = None,
1794+
optimize: Literal[-1, 0, 1, 2] = -1,
1795+
module: str | None = None,
1796+
) -> FunctionType: ...
1797+
@overload
1798+
def parse(
1799+
source: str | ReadableBuffer,
1800+
*,
1801+
mode: Literal["single"],
1802+
type_comments: bool = False,
1803+
feature_version: None | int | tuple[int, int] = None,
1804+
optimize: Literal[-1, 0, 1, 2] = -1,
1805+
module: str | None = None,
1806+
) -> Interactive: ...
1807+
@overload
1808+
def parse(
1809+
source: str | ReadableBuffer,
1810+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
1811+
mode: str = "exec",
1812+
*,
1813+
type_comments: bool = False,
1814+
feature_version: None | int | tuple[int, int] = None,
1815+
optimize: Literal[-1, 0, 1, 2] = -1,
1816+
module: str | None = None,
1817+
) -> mod: ...
1818+
1819+
elif sys.version_info >= (3, 13):
16761820
@overload
16771821
def parse(
16781822
source: _T,
@@ -1843,7 +1987,18 @@ else:
18431987

18441988
def literal_eval(node_or_string: str | AST) -> Any: ...
18451989

1846-
if sys.version_info >= (3, 13):
1990+
if sys.version_info >= (3, 15):
1991+
def dump(
1992+
node: AST,
1993+
annotate_fields: bool = True,
1994+
include_attributes: bool = False,
1995+
*,
1996+
indent: int | str | None = None,
1997+
show_empty: bool = False,
1998+
color: bool = False,
1999+
) -> str: ...
2000+
2001+
elif sys.version_info >= (3, 13):
18472002
def dump(
18482003
node: AST,
18492004
annotate_fields: bool = True,

0 commit comments

Comments
 (0)