Skip to content

Commit 1573e3d

Browse files
committed
Merge branch 'main' into copy-free-vars-in-bytecode
2 parents 4fbaa99 + 21fa7a3 commit 1573e3d

Some content is hidden

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

53 files changed

+1666
-673
lines changed

Doc/library/importlib.rst

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,11 @@ ABC hierarchy::
383383
See :pep:`302` for the exact definition for a loader.
384384

385385
Loaders that wish to support resource reading should implement a
386-
``get_resource_reader(fullname)`` method as specified by
386+
:meth:`get_resource_reader` method as specified by
387387
:class:`importlib.abc.ResourceReader`.
388388

389389
.. versionchanged:: 3.7
390-
Introduced the optional ``get_resource_reader()`` method.
390+
Introduced the optional :meth:`get_resource_reader` method.
391391

392392
.. method:: create_module(spec)
393393

@@ -405,80 +405,82 @@ ABC hierarchy::
405405

406406
An abstract method that executes the module in its own namespace
407407
when a module is imported or reloaded. The module should already
408-
be initialized when ``exec_module()`` is called. When this method exists,
409-
:meth:`~importlib.abc.Loader.create_module` must be defined.
408+
be initialized when :meth:`exec_module` is called. When this method exists,
409+
:meth:`create_module` must be defined.
410410

411411
.. versionadded:: 3.4
412412

413413
.. versionchanged:: 3.6
414-
:meth:`~importlib.abc.Loader.create_module` must also be defined.
414+
:meth:`create_module` must also be defined.
415415

416416
.. method:: load_module(fullname)
417417

418-
A legacy method for loading a module. If the module cannot be
418+
A legacy method for loading a module. If the module cannot be
419419
loaded, :exc:`ImportError` is raised, otherwise the loaded module is
420420
returned.
421421

422422
If the requested module already exists in :data:`sys.modules`, that
423423
module should be used and reloaded.
424424
Otherwise the loader should create a new module and insert it into
425425
:data:`sys.modules` before any loading begins, to prevent recursion
426-
from the import. If the loader inserted a module and the load fails, it
426+
from the import. If the loader inserted a module and the load fails, it
427427
must be removed by the loader from :data:`sys.modules`; modules already
428428
in :data:`sys.modules` before the loader began execution should be left
429429
alone (see :func:`importlib.util.module_for_loader`).
430430

431-
The loader should set several attributes on the module.
432-
(Note that some of these attributes can change when a module is
431+
The loader should set several attributes on the module
432+
(note that some of these attributes can change when a module is
433433
reloaded):
434434

435435
- :attr:`__name__`
436-
The name of the module.
436+
The module's fully-qualified name.
437+
It is ``'__main__'`` for an executed module.
437438

438439
- :attr:`__file__`
439-
The path to where the module data is stored (not set for built-in
440-
modules).
440+
The location the :term:`loader` used to load the module.
441+
For example, for modules loaded from a .py file this is the filename.
442+
It is not set on all modules (e.g. built-in modules).
441443

442444
- :attr:`__cached__`
443-
The path to where a compiled version of the module is/should be
444-
stored (not set when the attribute would be inappropriate).
445+
The filename of a compiled version of the module's code.
446+
It is not set on all modules (e.g. built-in modules).
445447

446448
- :attr:`__path__`
447-
A list of strings specifying the search path within a
448-
package. This attribute is not set on modules.
449+
The list of locations where the package's submodules will be found.
450+
Most of the time this is a single directory.
451+
The import system passes this attribute to ``__import__()`` and to finders
452+
in the same way as :attr:`sys.path` but just for the package.
453+
It is not set on non-package modules so it can be used
454+
as an indicator that the module is a package.
449455

450456
- :attr:`__package__`
451-
The fully-qualified name of the package under which the module was
452-
loaded as a submodule (or the empty string for top-level modules).
453-
For packages, it is the same as :attr:`__name__`. The
454-
:func:`importlib.util.module_for_loader` decorator can handle the
455-
details for :attr:`__package__`.
457+
The fully-qualified name of the package the module is in (or the
458+
empty string for a top-level module).
459+
If the module is a package then this is the same as :attr:`__name__`.
456460

457461
- :attr:`__loader__`
458-
The loader used to load the module. The
459-
:func:`importlib.util.module_for_loader` decorator can handle the
460-
details for :attr:`__package__`.
462+
The :term:`loader` used to load the module.
461463

462464
When :meth:`exec_module` is available then backwards-compatible
463465
functionality is provided.
464466

465467
.. versionchanged:: 3.4
466468
Raise :exc:`ImportError` when called instead of
467-
:exc:`NotImplementedError`. Functionality provided when
469+
:exc:`NotImplementedError`. Functionality provided when
468470
:meth:`exec_module` is available.
469471

470472
.. deprecated:: 3.4
471473
The recommended API for loading a module is :meth:`exec_module`
472-
(and :meth:`create_module`). Loaders should implement
473-
it instead of load_module(). The import machinery takes care of
474-
all the other responsibilities of load_module() when exec_module()
475-
is implemented.
474+
(and :meth:`create_module`). Loaders should implement it instead of
475+
:meth:`load_module`. The import machinery takes care of all the
476+
other responsibilities of :meth:`load_module` when
477+
:meth:`exec_module` is implemented.
476478

477479
.. method:: module_repr(module)
478480

479-
A legacy method which when implemented calculates and returns the
480-
given module's repr, as a string. The module type's default repr() will
481-
use the result of this method as appropriate.
481+
A legacy method which when implemented calculates and returns the given
482+
module's representation, as a string. The module type's default
483+
:meth:`__repr__` will use the result of this method as appropriate.
482484

483485
.. versionadded:: 3.3
484486

@@ -1420,69 +1422,80 @@ find and load modules.
14201422
.. class:: ModuleSpec(name, loader, *, origin=None, loader_state=None, is_package=None)
14211423

14221424
A specification for a module's import-system-related state. This is
1423-
typically exposed as the module's ``__spec__`` attribute. In the
1425+
typically exposed as the module's :attr:`__spec__` attribute. In the
14241426
descriptions below, the names in parentheses give the corresponding
1425-
attribute available directly on the module object.
1426-
E.g. ``module.__spec__.origin == module.__file__``. Note however that
1427+
attribute available directly on the module object,
1428+
e.g. ``module.__spec__.origin == module.__file__``. Note, however, that
14271429
while the *values* are usually equivalent, they can differ since there is
1428-
no synchronization between the two objects. Thus it is possible to update
1429-
the module's ``__path__`` at runtime, and this will not be automatically
1430-
reflected in ``__spec__.submodule_search_locations``.
1430+
no synchronization between the two objects. For example, it is possible to update
1431+
the module's :attr:`__file__` at runtime and this will not be automatically
1432+
reflected in the module's :attr:`__spec__.origin`, and vice versa.
14311433

14321434
.. versionadded:: 3.4
14331435

14341436
.. attribute:: name
14351437

1436-
(``__name__``)
1438+
(:attr:`__name__`)
14371439

1438-
A string for the fully-qualified name of the module.
1440+
The module's fully-qualified name.
1441+
The :term:`finder` should always set this attribute to a non-empty string.
14391442

14401443
.. attribute:: loader
14411444

1442-
(``__loader__``)
1445+
(:attr:`__loader__`)
14431446

1444-
The :term:`Loader <loader>` that should be used when loading
1445-
the module. :term:`Finders <finder>` should always set this.
1447+
The :term:`loader` used to load the module.
1448+
The :term:`finder` should always set this attribute.
14461449

14471450
.. attribute:: origin
14481451

1449-
(``__file__``)
1452+
(:attr:`__file__`)
14501453

1451-
Name of the place from which the module is loaded, e.g. "builtin" for
1452-
built-in modules and the filename for modules loaded from source.
1453-
Normally "origin" should be set, but it may be ``None`` (the default)
1454-
which indicates it is unspecified (e.g. for namespace packages).
1454+
The location the :term:`loader` should use to load the module.
1455+
For example, for modules loaded from a .py file this is the filename.
1456+
The :term:`finder` should always set this attribute to a meaningful value
1457+
for the :term:`loader` to use. In the uncommon case that there is not one
1458+
(like for namespace packages), it should be set to ``None``.
14551459

14561460
.. attribute:: submodule_search_locations
14571461

1458-
(``__path__``)
1462+
(:attr:`__path__`)
14591463

1460-
List of strings for where to find submodules, if a package (``None``
1461-
otherwise).
1464+
The list of locations where the package's submodules will be found.
1465+
Most of the time this is a single directory.
1466+
The :term:`finder` should set this attribute to a list, even an empty one, to indicate
1467+
to the import system that the module is a package. It should be set to ``None`` for
1468+
non-package modules. It is set automatically later to a special object for
1469+
namespace packages.
14621470

14631471
.. attribute:: loader_state
14641472

1465-
Container of extra module-specific data for use during loading (or
1466-
``None``).
1473+
The :term:`finder` may set this attribute to an object containing additional,
1474+
module-specific data to use when loading the module. Otherwise it should be
1475+
set to ``None``.
14671476

14681477
.. attribute:: cached
14691478

1470-
(``__cached__``)
1479+
(:attr:`__cached__`)
14711480

1472-
String for where the compiled module should be stored (or ``None``).
1481+
The filename of a compiled version of the module's code.
1482+
The :term:`finder` should always set this attribute but it may be ``None``
1483+
for modules that do not need compiled code stored.
14731484

14741485
.. attribute:: parent
14751486

1476-
(``__package__``)
1487+
(:attr:`__package__`)
14771488

1478-
(Read-only) The fully-qualified name of the package under which the module
1479-
should be loaded as a submodule (or the empty string for top-level modules).
1480-
For packages, it is the same as :attr:`__name__`.
1489+
(Read-only) The fully-qualified name of the package the module is in (or the
1490+
empty string for a top-level module).
1491+
If the module is a package then this is the same as :attr:`name`.
14811492

14821493
.. attribute:: has_location
14831494

1484-
Boolean indicating whether or not the module's "origin"
1485-
attribute refers to a loadable location.
1495+
``True`` if the spec's :attr:`origin` refers to a loadable location,
1496+
``False`` otherwise. This value impacts how :attr:`origin` is interpreted
1497+
and how the module's :attr:`__file__` is populated.
1498+
14861499

14871500
:mod:`importlib.util` -- Utility code for importers
14881501
---------------------------------------------------
@@ -1574,8 +1587,9 @@ an :term:`importer`.
15741587

15751588
:exc:`ImportError` is raised if **name** is a relative module name but
15761589
**package** is a false value (e.g. ``None`` or the empty string).
1577-
:exc:`ImportError` is also raised a relative name would escape its containing
1578-
package (e.g. requesting ``..bacon`` from within the ``spam`` package).
1590+
:exc:`ImportError` is also raised if a relative name would escape its
1591+
containing package (e.g. requesting ``..bacon`` from within the ``spam``
1592+
package).
15791593

15801594
.. versionadded:: 3.3
15811595

Doc/library/netrc.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ the Unix :program:`ftp` program and other FTP clients.
4141
.. versionchanged:: 3.10
4242
:class:`netrc` try UTF-8 encoding before using locale specific
4343
encoding.
44+
The entry in the netrc file no longer needs to contain all tokens. The missing
45+
tokens' value default to an empty string. All the tokens and their values now
46+
can contain arbitrary characters, like whitespace and non-ASCII characters.
47+
If the login name is anonymous, it won't trigger the security check.
4448

4549

4650
.. exception:: NetrcParseError
@@ -85,10 +89,3 @@ Instances of :class:`~netrc.netrc` have public instance variables:
8589
.. attribute:: netrc.macros
8690

8791
Dictionary mapping macro names to string lists.
88-
89-
.. note::
90-
91-
Passwords are limited to a subset of the ASCII character set. All ASCII
92-
punctuation is allowed in passwords, however, note that whitespace and
93-
non-printable characters are not allowed in passwords. This is a limitation
94-
of the way the .netrc file is parsed and may be removed in the future.

Doc/library/time.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,17 @@ Functions
362362
On Windows, if *secs* is zero, the thread relinquishes the remainder of its
363363
time slice to any other thread that is ready to run. If there are no other
364364
threads ready to run, the function returns immediately, and the thread
365-
continues execution.
365+
continues execution. On Windows 8.1 and newer the implementation uses
366+
a `high-resolution timer
367+
<https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers>`_
368+
which provides resolution of 100 nanoseconds. If *secs* is zero, ``Sleep(0)`` is used.
366369

367370
Unix implementation:
368371

369372
* Use ``clock_nanosleep()`` if available (resolution: 1 nanosecond);
370373
* Or use ``nanosleep()`` if available (resolution: 1 nanosecond);
371374
* Or use ``select()`` (resolution: 1 microsecond).
372375

373-
On Windows, a waitable timer is used (resolution: 100 nanosecond). If *secs* is
374-
zero, ``Sleep(0)`` is used.
375-
376376
.. versionchanged:: 3.11
377377
On Unix, the ``clock_nanosleep()`` and ``nanosleep()`` functions are now
378378
used if available. On Windows, a waitable timer is now used.

Doc/library/unittest.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Command-line options
227227

228228
Only run test methods and classes that match the pattern or substring.
229229
This option may be used multiple times, in which case all test cases that
230-
match of the given patterns are included.
230+
match any of the given patterns are included.
231231

232232
Patterns that contain a wildcard character (``*``) are matched against the
233233
test name using :meth:`fnmatch.fnmatchcase`; otherwise simple case-sensitive

Doc/whatsnew/3.11.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ threading
269269
by system clock changes.
270270
(Contributed by Victor Stinner in :issue:`41710`.)
271271

272+
272273
time
273274
----
274275

@@ -278,10 +279,13 @@ time
278279
of 1 microsecond (10\ :sup:`-6` seconds).
279280
(Contributed by Benjamin Szőke and Victor Stinner in :issue:`21302`.)
280281

281-
* On Windows, :func:`time.sleep` now uses a waitable timer which has a
282-
resolution of 100 nanoseconds (10\ :sup:`-7` seconds). Previously, it had
283-
a resolution of 1 millisecond (10\ :sup:`-3` seconds).
284-
(Contributed by Benjamin Szőke and Victor Stinner in :issue:`21302`.)
282+
* On Windows 8.1 and newer, :func:`time.sleep` now uses a waitable timer based
283+
on `high-resolution timers
284+
<https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers>`_
285+
which has a resolution of 100 nanoseconds (10\ :sup:`-7` seconds). Previously,
286+
it had a resolution of 1 millisecond (10\ :sup:`-3` seconds).
287+
(Contributed by Benjamin Szőke, Dong-hee Na, Eryk Sun and Victor Stinner in :issue:`21302` and :issue:`45429`.)
288+
285289

286290
unicodedata
287291
-----------

Include/internal/pycore_abstract.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ _PyIndex_Check(PyObject *obj)
1616
return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
1717
}
1818

19+
PyObject *_PyNumber_PowerNoMod(PyObject *lhs, PyObject *rhs);
20+
PyObject *_PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs);
21+
1922
#ifdef __cplusplus
2023
}
2124
#endif

Include/internal/pycore_code.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef struct {
1717
uint8_t original_oparg;
1818
uint8_t counter;
1919
uint16_t index;
20+
uint32_t version;
2021
} _PyAdaptiveEntry;
2122

2223

@@ -266,7 +267,7 @@ int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name
266267
int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
267268
int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
268269
int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
269-
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
270+
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
270271
int _Py_Specialize_CallFunction(PyObject *callable, _Py_CODEUNIT *instr, int nargs, SpecializedCacheEntry *cache, PyObject *builtins);
271272
void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
272273
SpecializedCacheEntry *cache);

Include/internal/pycore_long.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static inline PyObject* _PyLong_GetOne(void)
2323

2424
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
2525
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
26+
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
2627

2728
/* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
2829
_PyBytes_DecodeEscape(), etc. */

0 commit comments

Comments
 (0)