8000 Merge branch 'main' into gh-124693 · savannahostrowski/cpython@e5cf7d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e5cf7d1

Browse files
Merge branch 'main' into pythongh-124693
2 parents e072c60 + 7d2c397 commit e5cf7d1

File tree

130 files changed

+3767
-2589
lines changed

Some content is hidden

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

130 files changed

+3767
-2589
lines changed

Doc/c-api/import.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ Importing Modules
136136
such modules have no way to know that the module object is an unknown (and
137137
probably damaged with respect to the module author's intents) state.
138138
139-
The module's :attr:`__spec__` and :attr:`__loader__` will be set, if
140-
not set already, with the appropriate values. The spec's loader will
141-
be set to the module's ``__loader__`` (if set) and to an instance of
142-
:class:`~importlib.machinery.SourceFileLoader` otherwise.
139+
The module's :attr:`~module.__spec__` and :attr:`~module.__loader__` will be
140+
set, if not set already, with the appropriate values. The spec's loader
141+
will be set to the module's :attr:`!__loader__` (if set) and to an instance
142+
of :class:`~importlib.machinery.SourceFileLoader` otherwise.
143143
144-
The module's :attr:`__file__` attribute will be set to the code object's
145-
:attr:`~codeobject.co_filename`. If applicable, :attr:`__cached__` will also
146-
be set.
144+
The module's :attr:`~module.__file__` attribute will be set to the code
145+
object's :attr:`~codeobject.co_filename`. If applicable,
146+
:attr:`~module.__cached__` will also be set.
147147
148148
This function will reload the module if it was already imported. See
149149
:c:func:`PyImport_ReloadModule` for the intended way to reload a module.
@@ -155,29 +155,29 @@ Importing Modules
155155
:c:func:`PyImport_ExecCodeModuleWithPathnames`.
156156
157157
.. versionchanged:: 3.12
158-
The setting of :attr:`__cached__` and :attr:`__loader__` is
159-
deprecated. See :class:`~importlib.machinery.ModuleSpec` for
158+
The setting of :attr:`~module.__cached__` and :attr:`~module.__loader__`
159+
is deprecated. See :class:`~importlib.machinery.ModuleSpec` for
160160
alternatives.
161161
162162
163163
.. c:function:: PyObject* PyImport_ExecCodeModuleEx(const char *name, PyObject *co, const char *pathname)
164164
165-
Like :c:func:`PyImport_ExecCodeModule`, but the :attr:`__file__` attribute of
166-
the module object is set to *pathname* if it is non-``NULL``.
165+
Like :c:func:`PyImport_ExecCodeModule`, but the :attr:`~module.__file__`
166+
attribute of the module object is set to *pathname* if it is non-``NULL``.
167167
168168
See also :c:func:`PyImport_ExecCodeModuleWithPathnames`.
169169
170170
171171
.. c:function:: PyObject* PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, PyObject *cpathname)
172172
173-
Like :c:func:`PyImport_ExecCodeModuleEx`, but the :attr:`__cached__`
173+
Like :c:func:`PyImport_ExecCodeModuleEx`, but the :attr:`~module.__cached__`
174174
attribute of the module object is set to *cpathname* if it is
175175
non-``NULL``. Of the three functions, this is the preferred one to use.
176176
177177
.. versionadded:: 3.3
178178
179179
.. versionchanged:: 3.12
180-
Setting :attr:`__cached__` is deprecated. See
180+
Setting :attr:`~module.__cached__` is deprecated. See
181181
:class:`~importlib.machinery.ModuleSpec` for alternatives.
182182
183183

Doc/c-api/module.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ Module Objects
3737
single: __package__ (module attribute)
3838
single: __loader__ (module attribute)
3939
40-
Return a new module object with the :attr:`__name__` attribute set to *name*.
41-
The module's :attr:`__name__`, :attr:`__doc__`, :attr:`__package__`, and
42-
:attr:`__loader__` attributes are filled in (all but :attr:`__name__` are set
43-
to ``None``); the caller is responsible for providing a :attr:`__file__`
44-
attribute.
40+
Return a new module object with :attr:`module.__name__` set to *name*.
41+
The module's :attr:`!__name__`, :attr:`~module.__doc__`,
42+
:attr:`~module.__package__` and :attr:`~module.__loader__` attributes are
43+
filled in (all but :attr:`!__name__` are set to ``None``). The caller is
44+
responsible for setting a :attr:`~module.__file__` attribute.
4545
4646
Return ``NULL`` with an exception set on error.
4747
4848
.. versionadded:: 3.3
4949
5050
.. versionchanged:: 3.4
51-
:attr:`__package__` and :attr:`__loader__` are set to ``None``.
51+
:attr:`~module.__package__` and :attr:`~module.__loader__` are now set to
52+
``None``.
5253
5354
5455
.. c:function:: PyObject* PyModule_New(const char *name)
@@ -77,8 +78,9 @@ Module Objects
7778
single: __name__ (module attribute)
7879
single: SystemError (built-in exception)
7980
80-
Return *module*'s :attr:`__name__` value. If the module does not provide one,
81-
or if it is not a string, :exc:`SystemError` is raised and ``NULL`` is returned.
81+
Return *module*'s :attr:`~module.__name__` value. If the module does not
82+
provide one, or if it is not a string, :exc:`SystemError` is raised and
83+
``NULL`` is returned.
8284
8385
.. versionadded:: 3.3
8486
@@ -108,8 +110,8 @@ Module Objects
108110
single: SystemError (built-in exception)
109111
110112
Return the name of the file from which *module* was loaded using *module*'s
111-
:attr:`__file__` attribute. If this is not defined, or if it is not a
112-
unicode string, raise :exc:`SystemError` and return ``NULL``; otherwise return
113+
:attr:`~module.__file__` attribute. If this is not defined, or if it is not a
114+
string, raise :exc:`SystemError` and return ``NULL``; otherwise return
113115
a reference to a Unicode object.
114116
115117
.. versionadded:: 3.2

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
extensions = [
2323
'audit_events',
24+
'availability',
2425
'c_annotations',
2526
'glossary_search',
2627
'lexers',

Doc/deprecations/pending-removal-in-3.14.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Pending Removal in Python 3.14
22
------------------------------
33

4+
* The import system:
5+
6+
* Setting :attr:`~module.__loader__` on a module while
7+
failing to set :attr:`__spec__.loader <importlib.machinery.ModuleSpec.loader>`
8+
is deprecated. In Python 3.14, :attr:`!__loader__` will cease to be set or
9+
taken into consideration by the import system or the standard library.
10+
411
* :mod:`argparse`: The *type*, *choices*, and *metavar* parameters
512
of :class:`!argparse.BooleanOptionalAction` are deprecated
613
and will be removed in 3.14.

Doc/deprecations/pending-removal-in-3.15.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
Pending Removal in Python 3.15
22
------------------------------
33

4+
* The import system:
5+
6+
* Setting :attr:`~module.__cached__` on a module while
7+
failing to set :attr:`__spec__.cached <importlib.machinery.ModuleSpec.cached>`
8+
is deprecated. In Python 3.15, :attr:`!__cached__` will cease to be set or
9+
take into consideration by the import system or standard library. (:gh:`97879`)
10+
11+
* Setting :attr:`~module.__package__` on a module while
12+
failing to set :attr:`__spec__.parent <importlib.machinery.ModuleSpec.parent>`
13+
is deprecated. In Python 3.15, :attr:`!__package__` will cease to be set or
14+
take into consideration by the import system or standard library. (:gh:`97879`)
15+
416
* :mod:`ctypes`:
517

618
* The undocumented :func:`!ctypes.SetPointerType` function
@@ -17,9 +29,6 @@ Pending Removal in Python 3.15
1729
* The :option:`!--cgi` flag to the :program:`python -m http.server`
1830
command-line interface has been deprecated since Python 3.13.
1931

20-
* :mod:`importlib`: ``__package__`` and ``__cached__`` will cease to be set or
21-
taken into consideration by the import system (:gh:`97879`).
22-
2332
* :class:`locale`:
2433

2534
* The :func:`~locale.getdefaultlocale` function

Doc/glossary.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Glossary
461461
<meta path finder>` for use with :data:`sys.meta_path`, and :term:`path
462462
entry finders <path entry finder>` for use with :data:`sys.path_hooks`.
463463

464-
See :ref:`importsystem` and :mod:`importlib` for much more detail.
464+
See :ref:`finders-and-loaders` and :mod:`importlib` for much more detail.
465465

466466
floor division
467467
Mathematical division that rounds down to nearest integer. The floor
@@ -791,8 +791,11 @@ Glossary
791791
loader
792792
An object that loads a module. It must define a method named
793793
:meth:`load_module`. A loader is typically returned by a
794-
:term:`finder`. See :pep:`302` for details and
795-
:class:`importlib.abc.Loader` for an :term:`abstract base class`.
794+
:term:`finder`. See also:
795+
796+
* :ref:`finders-and-loaders`
797+
* :class:`importlib.abc.Loader`
798+
* :pep:`302`
796799

797800
locale encoding
798801
On Unix, it is the encoding of the LC_CTYPE locale. It can be set with
@@ -862,6 +865,8 @@ Glossary
862865
A namespace containing the import-related information used to load a
863866
module. An instance of :class:`importlib.machinery.ModuleSpec`.
864867

868+
See also :ref:`module-specs`.
869+
865870
MRO
866871
See :term:`method resolution order`.
867872

Doc/howto/argparse-optparse.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.. currentmodule:: argparse
2+
3+
.. _upgrading-optparse-code:
4+
5+
==========================
6+
Upgrading optparse code
7+
==========================
8+
9+
Originally, the :mod:`argparse` module had attempted to maintain compatibility
10+
with :mod:`optparse`. However, :mod:`optparse` was difficult to extend
11+
transparently, particularly with the changes required to support
12+
``nargs=`` specifiers and better usage messages. When most everything in
13+
:mod:`optparse` had either been copy-pasted over or monkey-patched, it no
14+
longer seemed practical to try to maintain the backwards compatibility.
15+
16+
The :mod:`argparse` module improves on the :mod:`optparse`
17+
module in a number of ways including:
18+
19+
* Handling positional arguments.
20+
* Supporting subcommands.
21+
* Allowing alternative option prefixes like ``+`` and ``/``.
22+
* Handling zero-or-more and one-or-more style arguments.
23+
* Producing more informative usage messages.
24+
* Providing a much simpler interface for custom ``type`` and ``action``.
25+
26+
A partial upgrade path from :mod:`optparse` to :mod:`argparse`:
27+
28+
* Replace all :meth:`optparse.OptionParser.add_option` calls with
29+
:meth:`ArgumentParser.add_argument` calls.
30+
31+
* Replace ``(options, args) = parser.parse_args()`` with ``args =
32+
parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
33+
calls for the positional arguments. Keep in mind that what was previously
34+
called ``options``, now in the :mod:`argparse` context is called ``args``.
35+
36+
* Replace :meth:`optparse.OptionParser.disable_interspersed_args`
37+
by using :meth:`~ArgumentParser.parse_intermixed_args` instead of
38+
:meth:`~ArgumentParser.parse_args`.
39+
40+
* Replace callback actions and the ``callback_*`` keyword arguments with
41+
``type`` or ``action`` arguments.
42+
43+
* Replace string names for ``type`` keyword arguments with the corresponding
44+
type objects (e.g. int, float, complex, etc).
45+
46+
* Replace :class:`optparse.Values` with :class:`Namespace` and
47+
:exc:`optparse.OptionError` and :exc:`optparse.OptionValueError` with
48+
:exc:`ArgumentError`.
49+
50+
* Replace strings with implicit arguments such as ``%default`` or ``%prog`` with
51+
the standard Python syntax to use dictionaries to format strings, that is,
52+
``%(default)s`` and ``%(prog)s``.
53+
54+
* Replace the OptionParser constructor ``version`` argument with a call to
55+
``parser.add_argument('--version', action='version', version='<the version>')``.

Doc/includes/newtypes/custom2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2323
CustomObject *self;
2424
self = (CustomObject *) type->tp_alloc(type, 0);
2525
if (self != NULL) {
26-
self->first = PyUnicode_FromString("");
26+
self->first = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
2727
if (self->first == NULL) {
2828
Py_DECREF(self);
2929
return NULL;
3030
}
31-
self->last = PyUnicode_FromString("");
31+
self->last = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
3232
if (self->last == NULL) {
3333
Py_DECREF(self);
3434
return NULL;

Doc/includes/newtypes/custom3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2323
CustomObject *self;
2424
self = (CustomObject *) type->tp_alloc(type, 0);
2525
if (self != NULL) {
26-
self->first = PyUnicode_FromString("");
26+
self->first = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
2727
if (self->first == NULL) {
2828
Py_DECREF(self);
2929
return NULL;
3030
}
31-
self->last = PyUnicode_FromString("");
31+
self->last = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
3232
if (self->last == NULL) {
3333
Py_DECREF(self);
3434
return NULL;

Doc/includes/newtypes/custom4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@ 863A @ -39,12 +39,12 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3939
CustomObject *self;
4040
self = (CustomObject *) type->tp_alloc(type, 0);
4141
if (self != NULL) {
42-
self->first = PyUnicode_FromString("");
42+
self->first = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
4343
if (self->first == NULL) {
4444
Py_DECREF(self);
4545
return NULL;
4646
}
47-
self->last = PyUnicode_FromString("");
47+
self->last = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
4848
if (self->last == NULL) {
4949
Py_DECREF(self);
5050
return NULL;

0 commit comments

Comments
 (0)
0