Skip to content

Commit e37970c

Browse files
Merge branch 'main' into fix/pickle-reduce-args-tuple-check
2 parents 5992976 + 7e2c9bd commit e37970c

File tree

16 files changed

+226
-46
lines changed

16 files changed

+226
-46
lines changed

Doc/howto/logging-cookbook.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ messages should not. Here's how you can achieve this::
229229
# tell the handler to use this format
230230
console.setFormatter(formatter)
231231
# add the handler to the root logger
232-
logging.getLogger('').addHandler(console)
232+
logging.getLogger().addHandler(console)
233233

234234
# Now, we can log to the root logger, or any other logger. First the root...
235235
logging.info('Jackdaws love my big sphinx of quartz.')
@@ -650,7 +650,7 @@ the receiving end. A simple way of doing this is attaching a
650650

651651
import logging, logging.handlers
652652

653-
rootLogger = logging.getLogger('')
653+
rootLogger = logging.getLogger()
654654
rootLogger.setLevel(logging.DEBUG)
655655
socketHandler = logging.handlers.SocketHandler('localhost',
656656
logging.handlers.DEFAULT_TCP_LOGGING_PORT)

Doc/library/inspect.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
262262
| | | ``yield from``, or |
263263
| | | ``None`` |
264264
+-----------------+-------------------+---------------------------+
265+
| | gi_state | state of the generator, |
266+
| | | one of ``GEN_CREATED``, |
267+
| | | ``GEN_RUNNING``, |
268+
| | | ``GEN_SUSPENDED``, or |
269+
| | | ``GEN_CLOSED`` |
270+
+-----------------+-------------------+---------------------------+
265271
| async generator | __name__ | name |
266272
+-----------------+-------------------+---------------------------+
267273
| | __qualname__ | qualified name |
@@ -278,6 +284,13 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
278284
+-----------------+-------------------+---------------------------+
279285
| | ag_code | code |
280286
+-----------------+-------------------+---------------------------+
287+
| | ag_state | state of the async |
288+
| | | generator, one of |
289+
| | | ``AGEN_CREATED``, |
290+
| | | ``AGEN_RUNNING``, |
291+
| | | ``AGEN_SUSPENDED``, or |
292+
| | | ``AGEN_CLOSED`` |
293+
+-----------------+-------------------+---------------------------+
281294
| coroutine | __name__ | name |
282295
+-----------------+-------------------+---------------------------+
283296
| | __qualname__ | qualified name |
@@ -298,6 +311,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
298311
| | | created, or ``None``. See |
299312
| | | |coroutine-origin-link| |
300313
+-----------------+-------------------+---------------------------+
314+
| | cr_state | state of the coroutine, |
315+
| | | one of ``CORO_CREATED``, |
316+
| | | ``CORO_RUNNING``, |
317+
| | | ``CORO_SUSPENDED``, or |
318+
| | | ``CORO_CLOSED`` |
319+
+-----------------+-------------------+---------------------------+
301320
| builtin | __doc__ | documentation string |
302321
+-----------------+-------------------+---------------------------+
303322
| | __name__ | original name of this |
@@ -341,6 +360,11 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
341360

342361
Add ``f_generator`` attribute to frames.
343362

363+
.. versionchanged:: next
364+
365+
Add ``gi_state`` attribute to generators, ``cr_state`` attribute to
366+
coroutines, and ``ag_state`` attribute to async generators.
367+
344368
.. function:: getmembers(object[, predicate])
345369

346370
Return all the members of an object in a list of ``(name, value)``

Doc/library/os.path.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ the :mod:`glob` module.)
9797

9898
.. function:: commonprefix(list, /)
9999

100-
Return the longest path prefix (taken character-by-character) that is a
101-
prefix of all paths in *list*. If *list* is empty, return the empty string
100+
Return the longest string prefix (taken character-by-character) that is a
101+
prefix of all strings in *list*. If *list* is empty, return the empty string
102102
(``''``).
103103

104-
.. note::
104+
.. warning::
105105

106106
This function may return invalid paths because it works a
107-
character at a time. To obtain a valid path, see
108-
:func:`commonpath`.
107+
character at a time.
108+
If you need a **common path prefix**, then the algorithm
109+
implemented in this function is not secure. Use
110+
:func:`commonpath` for finding a common path prefix.
109111

110112
::
111113

Include/internal/pycore_frame.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,16 @@ extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code);
4444
/* other API */
4545

4646
typedef enum _framestate {
47-
FRAME_CREATED = -4,
48-
FRAME_SUSPENDED = -3,
49-
FRAME_SUSPENDED_YIELD_FROM = -2,
50-
FRAME_SUSPENDED_YIELD_FROM_LOCKED = -1,
51-
FRAME_EXECUTING = 0,
52-
FRAME_COMPLETED = 1,
53-
FRAME_CLEARED = 4
47+
FRAME_CREATED = 0,
48+
FRAME_SUSPENDED = 1,
49+
FRAME_SUSPENDED_YIELD_FROM = 2,
50+
FRAME_SUSPENDED_YIELD_FROM_LOCKED = 3,
51+
FRAME_EXECUTING = 4,
52+
FRAME_CLEARED = 5
5453
} PyFrameState;
5554

5655
#define FRAME_STATE_SUSPENDED(S) ((S) >= FRAME_SUSPENDED && (S) <= FRAME_SUSPENDED_YIELD_FROM_LOCKED)
57-
#define FRAME_STATE_FINISHED(S) ((S) >= FRAME_COMPLETED)
58-
56+
#define FRAME_STATE_FINISHED(S) ((S) == FRAME_CLEARED)
5957
#ifdef __cplusplus
6058
}
6159
#endif

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,23 @@ struct _Py_global_strings {
5858
} literals;
5959

6060
struct {
61+
STRUCT_FOR_ID(AGEN_CLOSED)
62+
STRUCT_FOR_ID(AGEN_CREATED)
63+
STRUCT_FOR_ID(AGEN_RUNNING)
64+
STRUCT_FOR_ID(AGEN_SUSPENDED)
6165
STRUCT_FOR_ID(CANCELLED)
66+
STRUCT_FOR_ID(CORO_CLOSED)
67+
STRUCT_FOR_ID(CORO_CREATED)
68+
STRUCT_FOR_ID(CORO_RUNNING)
69+
STRUCT_FOR_ID(CORO_SUSPENDED)
6270
STRUCT_FOR_ID(Emax)
6371
STRUCT_FOR_ID(Emin)
6472
STRUCT_FOR_ID(FINISHED)
6573
STRUCT_FOR_ID(False)
74+
STRUCT_FOR_ID(GEN_CLOSED)
75+
STRUCT_FOR_ID(GEN_CREATED)
76+
STRUCT_FOR_ID(GEN_RUNNING)
77+
STRUCT_FOR_ID(GEN_SUSPENDED)
6678
STRUCT_FOR_ID(JSONDecodeError)
6779
STRUCT_FOR_ID(PENDING)
6880
STRUCT_FOR_ID(Py_Repr)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/inspect.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,13 +1813,7 @@ def getgeneratorstate(generator):
18131813
GEN_SUSPENDED: Currently suspended at a yield expression.
18141814
GEN_CLOSED: Execution has completed.
18151815
"""
1816-
if generator.gi_running:
1817-
return GEN_RUNNING
1818-
if generator.gi_suspended:
1819-
return GEN_SUSPENDED
1820-
if generator.gi_frame is None:
1821-
return GEN_CLOSED
1822-
return GEN_CREATED
1816+
return generator.gi_state
18231817

18241818

18251819
def getgeneratorlocals(generator):
@@ -1855,13 +1849,7 @@ def getcoroutinestate(coroutine):
18551849
CORO_SUSPENDED: Currently suspended at an await expression.
18561850
CORO_CLOSED: Execution has completed.
18571851
"""
1858-
if coroutine.cr_running:
1859-
return CORO_RUNNING
1860-
if coroutine.cr_suspended:
1861-
return CORO_SUSPENDED
1862-
if coroutine.cr_frame is None:
1863-
return CORO_CLOSED
1864-
return CORO_CREATED
1852+
return coroutine.cr_state
18651853

18661854

18671855
def getcoroutinelocals(coroutine):
@@ -1894,13 +1882,7 @@ def getasyncgenstate(agen):
18941882
AGEN_SUSPENDED: Currently suspended at a yield expression.
18951883
AGEN_CLOSED: Execution has completed.
18961884
"""
1897-
if agen.ag_running:
1898-
return AGEN_RUNNING
1899-
if agen.ag_suspended:
1900-
return AGEN_SUSPENDED
1901-
if agen.ag_frame is None:
1902-
return AGEN_CLOSED
1903-
return AGEN_CREATED
1885+
return agen.ag_state
19041886

19051887

19061888
def getasyncgenlocals(agen):

Lib/test/test_generators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ def b():
13661366
>>> type(i)
13671367
<class 'generator'>
13681368
>>> [s for s in dir(i) if not s.startswith('_')]
1369-
['close', 'gi_code', 'gi_frame', 'gi_running', 'gi_suspended', 'gi_yieldfrom', 'send', 'throw']
1369+
['close', 'gi_code', 'gi_frame', 'gi_running', 'gi_state', 'gi_suspended', 'gi_yieldfrom', 'send', 'throw']
13701370
>>> from test.support import HAVE_DOCSTRINGS
13711371
>>> print(i.__next__.__doc__ if HAVE_DOCSTRINGS else 'Implement next(self).')
13721372
Implement next(self).

0 commit comments

Comments
 (0)