Skip to content

Commit 04b2a8f

Browse files
Merge branch 'main' into argparse-nargs-0-positional
2 parents f86e3ba + 2c050d4 commit 04b2a8f

Some content is hidden

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

64 files changed

+987
-773
lines changed

Doc/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,15 @@ serve:
305305

306306
# for development releases: always build
307307
.PHONY: autobuild-dev
308+
autobuild-dev: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
308309
autobuild-dev:
309-
$(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1'
310+
$(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
310311

311312
# for HTML-only rebuilds
312313
.PHONY: autobuild-dev-html
314+
autobuild-dev-html: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
313315
autobuild-dev-html:
314-
$(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1'
316+
$(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
315317

316318
# for stable releases: only build if not in pre-release stage (alpha, beta)
317319
# release candidate downloads are okay, since the stable tree can be in that stage

Doc/library/argparse.rst

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Quick Links for ArgumentParser
3030
========================= =========================================================================================================== ==================================================================================
3131
Name Description Values
3232
========================= =========================================================================================================== ==================================================================================
33-
prog_ The name of the program Defaults to ``os.path.basename(sys.argv[0])``
33+
prog_ The name of the program
3434
usage_ The string describing the program usage
3535
description_ A brief description of what the program does
3636
epilog_ Additional description of the program after the argument help
@@ -214,8 +214,8 @@ ArgumentParser objects
214214
as keyword arguments. Each parameter has its own more detailed description
215215
below, but in short they are:
216216

217-
* prog_ - The name of the program (default:
218-
``os.path.basename(sys.argv[0])``)
217+
* prog_ - The name of the program (default: generated from the ``__main__``
218+
module attributes and ``sys.argv[0]``)
219219

220220
* usage_ - The string describing the program usage (default: generated from
221221
arguments added to parser)
@@ -268,10 +268,18 @@ The following sections describe how each of these are used.
268268
prog
269269
^^^^
270270

271-
By default, :class:`ArgumentParser` objects use the base name
272-
(see :func:`os.path.basename`) of ``sys.argv[0]`` to determine
273-
how to display the name of the program in help messages. This default is almost
274-
always desirable because it will make the help messages match the name that was
271+
By default, :class:`ArgumentParser` calculates the name of the program
272+
to display in help messages depending on the way the Python inerpreter was run:
273+
274+
* The :func:`base name <os.path.basename>` of ``sys.argv[0]`` if a file was
275+
passed as argument.
276+
* The Python interpreter name followed by ``sys.argv[0]`` if a directory or
277+
a zipfile was passed as argument.
278+
* The Python interpreter name followed by ``-m`` followed by the
279+
module or package name if the :option:`-m` option was used.
280+
281+
This default is almost
282+
always desirable because it will make the help messages match the string that was
275283
used to invoke the program on the command line. For example, consider a file
276284
named ``myprogram.py`` with the following code::
277285

@@ -281,7 +289,7 @@ named ``myprogram.py`` with the following code::
281289
args = parser.parse_args()
282290

283291
The help for this program will display ``myprogram.py`` as the program name
284-
(regardless of where the program was invoked from):
292+
(regardless of where the program was invoked from) if it is run as a script:
285293

286294
.. code-block:: shell-session
287295
@@ -299,6 +307,17 @@ The help for this program will display ``myprogram.py`` as the program name
299307
-h, --help show this help message and exit
300308
--foo FOO foo help
301309
310+
If it is executed via the :option:`-m` option, the help will display a corresponding command line:
311+
312+
.. code-block:: shell-session
313+
314+
$ /usr/bin/python3 -m subdir.myprogram --help
315+
usage: python3 -m subdir.myprogram [-h] [--foo FOO]
316+
317+
options:
318+
-h, --help show this help message and exit
319+
--foo FOO foo help
320+
302321
To change this default behavior, another value can be supplied using the
303322
``prog=`` argument to :class:`ArgumentParser`::
304323

@@ -309,7 +328,8 @@ To change this default behavior, another value can be supplied using the
309328
options:
310329
-h, --help show this help message and exit
311330

312-
Note that the program name, whether determined from ``sys.argv[0]`` or from the
331+
Note that the program name, whether determined from ``sys.argv[0]``,
332+
from the ``__main__`` module attributes or from the
313333
``prog=`` argument, is available to help messages using the ``%(prog)s`` format
314334
specifier.
315335

@@ -324,6 +344,9 @@ specifier.
324344
-h, --help show this help message and exit
325345
--foo FOO foo of the myprogram program
326346

347+
.. versionchanged:: 3.14
348+
The default ``prog`` value now reflects how ``__main__`` was actually executed,
349+
rather than always being ``os.path.basename(sys.argv[0])``.
327350

328351
usage
329352
^^^^^

Doc/library/dataclasses.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ Module contents
399399
:func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass
400400
instance.
401401

402-
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None)
402+
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None, decorator=dataclass)
403403

404404
Creates a new dataclass with name *cls_name*, fields as defined
405405
in *fields*, base classes as given in *bases*, and initialized
@@ -415,6 +415,11 @@ Module contents
415415
of the dataclass is set to that value.
416416
By default, it is set to the module name of the caller.
417417

418+
The *decorator* parameter is a callable that will be used to create the dataclass.
419+
It should take the class object as a first argument and the same keyword arguments
420+
as :func:`@dataclass <dataclass>`. By default, the :func:`@dataclass <dataclass>`
421+
function is used.
422+
418423
This function is not strictly required, because any Python
419424
mechanism for creating a new class with :attr:`!__annotations__` can
420425
then apply the :func:`@dataclass <dataclass>` function to convert that class to
@@ -438,6 +443,9 @@ Module contents
438443
def add_one(self):
439444
return self.x + 1
440445

446+
.. versionadded:: 3.14
447+
Added the *decorator* parameter.
448+
441449
.. function:: replace(obj, /, **changes)
442450

443451
Creates a new object of the same type as *obj*, replacing

Doc/library/datetime.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ Instance attributes (read-only):
295295

296296
Between 0 and 86,399 inclusive.
297297

298+
.. caution::
299+
300+
It is a somewhat common bug for code to unintentionally use this attribute
301+
when it is actually intended to get a :meth:`~timedelta.total_seconds`
302+
value instead:
303+
304+
.. doctest::
305+
306+
>>> from datetime import timedelta
307+
>>> duration = timedelta(seconds=11235813)
308+
>>> duration.days, duration.seconds
309+
(130, 3813)
310+
>>> duration.total_seconds()
311+
11235813.0
298312

299313
.. attribute:: timedelta.microseconds
300314

@@ -351,7 +365,7 @@ Supported operations:
351365
| | same value. (2) |
352366
+--------------------------------+-----------------------------------------------+
353367
| ``-t1`` | Equivalent to ``timedelta(-t1.days, |
354-
| | -t1.seconds*, -t1.microseconds)``, |
368+
| | -t1.seconds, -t1.microseconds)``, |
355369
| | and to ``t1 * -1``. (1)(4) |
356370
+--------------------------------+-----------------------------------------------+
357371
| ``abs(t)`` | Equivalent to ``+t`` when ``t.days >= 0``, |

Doc/library/sys.monitoring.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ Registering and using tools
5050
*tool_id* must be in the range 0 to 5 inclusive.
5151
Raises a :exc:`ValueError` if *tool_id* is in use.
5252

53-
.. function:: free_tool_id(tool_id: int, /) -> None
53+
.. function:: clear_tool_id(tool_id: int, /) -> None
5454

55-
Should be called once a tool no longer requires *tool_id*.
55+
Unregister all events and callback functions associated with *tool_id*.
5656

57-
.. note::
57+
.. function:: free_tool_id(tool_id: int, /) -> None
5858

59-
:func:`free_tool_id` will not disable global or local events associated
60-
with *tool_id*, nor will it unregister any callback functions. This
61-
function is only intended to be used to notify the VM that the
62-
particular *tool_id* is no longer in use.
59+
Should be called once a tool no longer requires *tool_id*.
60+
Will call :func:`clear_tool_id` before releasing *tool_id*.
6361

6462
.. function:: get_tool(tool_id: int, /) -> str | None
6563

Doc/tools/extensions/patchlevel.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ def get_version_info():
7474

7575

7676
if __name__ == "__main__":
77-
print(format_version_info(get_header_version_info())[0])
77+
short_ver, full_ver = format_version_info(get_header_version_info())
78+
if sys.argv[1:2] == ["--short"]:
79+
print(short_ver)
80+
else:
81+
print(full_ver)

Doc/using/windows.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ available for application-local distributions.
2323

2424
As specified in :pep:`11`, a Python release only supports a Windows platform
2525
while Microsoft considers the platform under extended support. This means that
26-
Python |version| supports Windows 8.1 and newer. If you require Windows 7
27-
support, please install Python 3.8.
26+
Python |version| supports Windows 10 and newer. If you require Windows 7
27+
support, please install Python 3.8. If you require Windows 8.1 support,
28+
please install Python 3.12.
2829

2930
There are a number of different installers available for Windows, each with
3031
certain benefits and downsides.

Doc/whatsnew/3.13.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,9 @@ The free-threaded mode requires a different executable,
320320
usually called ``python3.13t`` or ``python3.13t.exe``.
321321
Pre-built binaries marked as *free-threaded* can be installed as part of
322322
the official :ref:`Windows <install-freethreaded-windows>`
323-
and :ref:`macOS <getting-and-installing-macpython>` installers,
323+
and :ref:`macOS <install-freethreaded-macos>` installers,
324324
or CPython can be built from source with the :option:`--disable-gil` option.
325325

326-
.. better macOS link pending
327-
https://github.com/python/cpython/issues/109975#issuecomment-2286391179
328-
329326
Free-threaded execution allows for full utilization of the available
330327
processing power by running threads in parallel on available CPU cores.
331328
While not all software will benefit from this automatically, programs

Doc/whatsnew/3.14.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ New Modules
202202
Improved Modules
203203
================
204204

205+
argparse
206+
--------
207+
208+
* The default value of the :ref:`program name <prog>` for
209+
:class:`argparse.ArgumentParser` now reflects the way the Python
210+
interpreter was instructed to find the ``__main__`` module code.
211+
(Contributed by Serhiy Storchaka and Alyssa Coghlan in :gh:`66436`.)
205212

206213
ast
207214
---

Include/cpython/code.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
extern "C" {
99
#endif
1010

11+
/* Total tool ids available */
12+
#define _PY_MONITORING_TOOL_IDS 8
1113
/* Count of all local monitoring events */
1214
#define _PY_MONITORING_LOCAL_EVENTS 10
1315
/* Count of all "real" monitoring events (not derived from other events) */
@@ -57,6 +59,8 @@ typedef struct {
5759
_Py_LocalMonitors active_monitors;
5860
/* The tools that are to be notified for events for the matching code unit */
5961
uint8_t *tools;
62+
/* The version of tools when they instrument the code */
63+
uintptr_t tool_versions[_PY_MONITORING_TOOL_IDS];
6064
/* Information to support line events */
6165
_PyCoLineInstrumentationData *lines;
6266
/* The tools that are to be notified for line events for the matching code unit */

0 commit comments

Comments
 (0)