Skip to content

Commit 7537fd5

Browse files
committed
Merge remote-tracking branch 'cpython/main' into bpo-42260
2 parents b568efe + cb8f491 commit 7537fd5

30 files changed

+464
-321
lines changed

Doc/c-api/init_config.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,16 @@ PyConfig
605605
606606
.. versionadded:: 3.10
607607
608-
.. c:member:: int no_debug_ranges
608+
.. c:member:: int code_debug_ranges
609609
610-
If equals to ``1``, disables the inclusion of the end line and column
610+
If equals to ``0``, disables the inclusion of the end line and column
611611
mappings in code objects. Also disables traceback printing carets to
612612
specific error locations.
613613
614-
Default: ``0``.
614+
Set to ``0`` by the :envvar:`PYTHONNODEBUGRANGES` environment variable
615+
and by the :option:`-X no_debug_ranges <-X>` command line option.
616+
617+
Default: ``1``.
615618
616619
.. versionadded:: 3.11
617620

Doc/library/asyncio-eventloop.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,10 @@ async/await code consider using the high-level
12431243

12441244
.. note::
12451245

1246-
The default asyncio event loop on **Windows** does not support
1247-
subprocesses. See :ref:`Subprocess Support on Windows
1248-
<asyncio-windows-subprocess>` for details.
1246+
On Windows, the default event loop :class:`ProactorEventLoop` supports
1247+
subprocesses, whereas :class:`SelectorEventLoop` does not. See
1248+
:ref:`Subprocess Support on Windows <asyncio-windows-subprocess>` for
1249+
details.
12491250

12501251
.. coroutinemethod:: loop.subprocess_exec(protocol_factory, *args, \
12511252
stdin=subprocess.PIPE, stdout=subprocess.PIPE, \

Doc/library/inspect.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,24 @@ attributes:
275275
listed in the metaclass' custom :meth:`__dir__`.
276276

277277

278+
.. function:: getmembers_static(object[, predicate])
279+
280+
Return all the members of an object in a list of ``(name, value)``
281+
pairs sorted by name without triggering dynamic lookup via the descriptor
282+
protocol, __getattr__ or __getattribute__. Optionally, only return members
283+
that satisfy a given predicate.
284+
285+
.. note::
286+
287+
:func:`getmembers_static` may not be able to retrieve all members
288+
that getmembers can fetch (like dynamically created attributes)
289+
and may find members that getmembers can't (like descriptors
290+
that raise AttributeError). It can also return descriptor objects
291+
instead of instance members in some cases.
292+
293+
.. versionadded:: 3.11
294+
295+
278296
.. function:: getmodulename(path)
279297

280298
Return the name of the module named by the file *path*, without including the

Doc/library/urllib.parse.rst

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,29 @@ or on combining URL components into a URL string.
4848
result, except for a leading slash in the *path* component, which is retained if
4949
present. For example:
5050

51+
.. doctest::
52+
:options: +NORMALIZE_WHITESPACE
53+
5154
>>> from urllib.parse import urlparse
52-
>>> o = urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
53-
>>> o # doctest: +NORMALIZE_WHITESPACE
54-
ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
55-
params='', query='', fragment='')
55+
>>> urlparse("scheme://netloc/path;parameters?query#fragment")
56+
ParseResult(scheme='scheme', netloc='netloc', path='/path;parameters', params='',
57+
query='query', fragment='fragment')
58+
>>> o = urlparse("http://docs.python.org:80/3/library/urllib.parse.html?"
59+
... "highlight=params#url-parsing")
60+
>>> o
61+
ParseResult(scheme='http', netloc='docs.python.org:80',
62+
path='/3/library/urllib.parse.html', params='',
63+
query='highlight=params', fragment='url-parsing')
5664
>>> o.scheme
5765
'http'
66+
>>> o.netloc
67+
'docs.python.org:80'
68+
>>> o.hostname
69+
'docs.python.org'
5870
>>> o.port
5971
80
60-
>>> o.geturl()
61-
'http://www.cwi.nl:80/%7Eguido/Python.html'
72+
>>> o._replace(fragment="").geturl()
73+
'http://docs.python.org:80/3/library/urllib.parse.html?highlight=params'
6274

6375
Following the syntax specifications in :rfc:`1808`, urlparse recognizes
6476
a netloc only if it is properly introduced by '//'. Otherwise the
@@ -92,31 +104,30 @@ or on combining URL components into a URL string.
92104
The return value is a :term:`named tuple`, which means that its items can
93105
be accessed by index or as named attributes, which are:
94106

95-
+------------------+-------+--------------------------+----------------------+
96-
| Attribute | Index | Value | Value if not present |
97-
+==================+=======+==========================+======================+
98-
| :attr:`scheme` | 0 | URL scheme specifier | *scheme* parameter |
99-
+------------------+-------+--------------------------+----------------------+
100-
| :attr:`netloc` | 1 | Network location part | empty string |
101-
+------------------+-------+--------------------------+----------------------+
102-
| :attr:`path` | 2 | Hierarchical path | empty string |
103-
+------------------+-------+--------------------------+----------------------+
104-
| :attr:`params` | 3 | Parameters for last path | empty string |
105-
| | | element | |
106-
+------------------+-------+--------------------------+----------------------+
107-
| :attr:`query` | 4 | Query component | empty string |
108-
+------------------+-------+--------------------------+----------------------+
109-
| :attr:`fragment` | 5 | Fragment identifier | empty string |
110-
+------------------+-------+--------------------------+----------------------+
111-
| :attr:`username` | | User name | :const:`None` |
112-
+------------------+-------+--------------------------+----------------------+
113-
| :attr:`password` | | Password | :const:`None` |
114-
+------------------+-------+--------------------------+----------------------+
115-
| :attr:`hostname` | | Host name (lower case) | :const:`None` |
116-
+------------------+-------+--------------------------+----------------------+
117-
| :attr:`port` | | Port number as integer, | :const:`None` |
118-
| | | if present | |
119-
+------------------+-------+--------------------------+----------------------+
107+
+------------------+-------+-------------------------+------------------------+
108+
| Attribute | Index | Value | Value if not present |
109+
+==================+=======+=========================+========================+
110+
| :attr:`scheme` | 0 | URL scheme specifier | *scheme* parameter |
111+
+------------------+-------+-------------------------+------------------------+
112+
| :attr:`netloc` | 1 | Network location part | empty string |
113+
+------------------+-------+-------------------------+------------------------+
114+
| :attr:`path` | 2 | Hierarchical path | empty string |
115+
+------------------+-------+-------------------------+------------------------+
116+
| :attr:`params` | 3 | No longer used | always an empty string |
117+
+------------------+-------+-------------------------+------------------------+
118+
| :attr:`query` | 4 | Query component | empty string |
119+
+------------------+-------+-------------------------+------------------------+
120+
| :attr:`fragment` | 5 | Fragment identifier | empty string |
121+
+------------------+-------+-------------------------+------------------------+
122+
| :attr:`username` | | User name | :const:`None` |
123+
+------------------+-------+-------------------------+------------------------+
124+
| :attr:`password` | | Password | :const:`None` |
125+
+------------------+-------+-------------------------+------------------------+
126+
| :attr:`hostname` | | Host name (lower case) | :const:`None` |
127+
+------------------+-------+-------------------------+------------------------+
128+
| :attr:`port` | | Port number as integer, | :const:`None` |
129+
| | | if present | |
130+
+------------------+-------+-------------------------+------------------------+
120131

121132
Reading the :attr:`port` attribute will raise a :exc:`ValueError` if
122133
an invalid port is specified in the URL. See section

Doc/whatsnew/3.11.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ fractions
207207
(Contributed by Mark Dickinson in :issue:`44547`.)
208208

209209

210+
inspect
211+
-------
212+
* Add :func:`inspect.getmembers_static`: return all members without
213+
triggering dynamic lookup via the descriptor protocol. (Contributed by
214+
Weipeng Hong in :issue:`30533`.)
215+
216+
210217
math
211218
----
212219
* Add :func:`math.exp2`: return 2 raised to the power of x.

Include/cpython/initconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ typedef struct PyConfig {
143143
int faulthandler;
144144
int tracemalloc;
145145
int import_time;
146-
int no_debug_ranges;
146+
int code_debug_ranges;
147147
int show_ref_count;
148148
int dump_refs;
149149
wchar_t *dump_refs_file;

Include/internal/pycore_code.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,25 @@ _GetSpecializedCacheEntryForInstruction(const _Py_CODEUNIT *first_instr, int nex
137137
#define QUICKENING_INITIAL_WARMUP_VALUE (-QUICKENING_WARMUP_DELAY)
138138
#define QUICKENING_WARMUP_COLDEST 1
139139

140-
static inline void
141-
PyCodeObject_IncrementWarmup(PyCodeObject * co)
142-
{
143-
co->co_warmup++;
144-
}
140+
int _Py_Quicken(PyCodeObject *code);
145141

146-
/* Used by the interpreter to determine when a code object should be quickened */
142+
/* Returns 1 if quickening occurs.
143+
* -1 if an error occurs
144+
* 0 otherwise */
147145
static inline int
148-
PyCodeObject_IsWarmedUp(PyCodeObject * co)
146+
_Py_IncrementCountAndMaybeQuicken(PyCodeObject *code)
149147
{
150-
return (co->co_warmup == 0);
148+
if (code->co_warmup != 0) {
149+
code->co_warmup++;
150+
if (code->co_warmup == 0) {
151+
return _Py_Quicken(code) ? -1 : 1;
152+
}
153+
}
154+
return 0;
151155
}
152156

153-
int _Py_Quicken(PyCodeObject *code);
154-
155157
extern Py_ssize_t _Py_QuickenedCount;
156158

157-
158159
/* "Locals plus" for a code object is the set of locals + cell vars +
159160
* free vars. This relates to variable names as well as offsets into
160161
* the "fast locals" storage array of execution frames. The compiler

Include/internal/pycore_frame.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ enum _framestate {
1919

2020
typedef signed char PyFrameState;
2121

22+
/*
23+
frame->f_lasti refers to the index of the last instruction,
24+
unless it's -1 in which case next_instr should be first_instr.
25+
*/
26+
2227
typedef struct _interpreter_frame {
2328
PyFunctionObject *f_func; /* Strong reference */
2429
PyObject *f_globals; /* Borrowed reference */

Include/pyport.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ Used in: Py_SAFE_DOWNCAST
8787

8888
/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
8989
the necessary integer types are available, and we're on a 64-bit platform
90-
(as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
90+
(as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits.
91+
92+
From pyodide: WASM has 32 bit pointers but has native 64 bit arithmetic
93+
so it is more efficient to use 30 bit digits.
94+
*/
9195

9296
#ifndef PYLONG_BITS_IN_DIGIT
93-
#if SIZEOF_VOID_P >= 8
94-
#define PYLONG_BITS_IN_DIGIT 30
97+
#if SIZEOF_VOID_P >= 8 || defined(__wasm__)
98+
# define PYLONG_BITS_IN_DIGIT 30
9599
#else
96-
#define PYLONG_BITS_IN_DIGIT 15
100+
# define PYLONG_BITS_IN_DIGIT 15
97101
#endif
98102
#endif
99103

Lib/platform.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,10 @@ def _syscmd_file(target, default=''):
607607
# XXX Others too ?
608608
return default
609609

610-
import subprocess
610+
try:
611+
import subprocess
612+
except ImportError:
613+
return default
611614
target = _follow_symlinks(target)
612615
# "file" output is locale dependent: force the usage of the C locale
613616
# to get deterministic behavior.
@@ -746,7 +749,10 @@ def from_subprocess():
746749
"""
747750
Fall back to `uname -p`
748751
"""
749-
import subprocess
752+
try:
753+
import subprocess
754+
except ImportError:
755+
return None
750756
try:
751757
return subprocess.check_output(
752758
['uname', '-p'],

0 commit comments

Comments
 (0)