Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 916ae8c

Browse files
Pull in main
2 parents 00d5abb + 22b8d77 commit 916ae8c

81 files changed

Lines changed: 3081 additions & 1027 deletions

File tree

Some content is hidden

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

Doc/c-api/exceptions.rst

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ Querying the error indicator
438438
439439
.. c:function:: void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
440440
441-
As of 3.12, this function is deprecated. Use :c:func:`PyErr_GetRaisedException` instead.
441+
.. deprecated:: 3.12
442+
443+
Use :c:func:`PyErr_GetRaisedException` instead.
442444
443445
Retrieve the error indicator into three variables whose addresses are passed.
444446
If the error indicator is not set, set all three variables to ``NULL``. If it is
@@ -447,8 +449,10 @@ Querying the error indicator
447449
448450
.. note::
449451
450-
This function is normally only used by code that needs to catch exceptions or
451-
by code that needs to save and restore the error indicator temporarily, e.g.::
452+
This function is normally only used by legacy code that needs to catch
453+
exceptions or save and restore the error indicator temporarily.
454+
455+
For example::
452456
453457
{
454458
PyObject *type, *value, *traceback;
@@ -459,15 +463,17 @@ Querying the error indicator
459463
PyErr_Restore(type, value, traceback);
460464
}
461465
462-
.. deprecated:: 3.12
463-
464466
465467
.. c:function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
466468
467-
As of 3.12, this function is deprecated. Use :c:func:`PyErr_SetRaisedException` instead.
469+
.. deprecated:: 3.12
470+
471+
Use :c:func:`PyErr_SetRaisedException` instead.
468472
469-
Set the error indicator from the three objects. If the error indicator is
470-
already set, it is cleared first. If the objects are ``NULL``, the error
473+
Set the error indicator from the three objects,
474+
*type*, *value*, and *traceback*,
475+
clearing the existing exception if one is set.
476+
If the objects are ``NULL``, the error
471477
indicator is cleared. Do not pass a ``NULL`` type and non-``NULL`` value or
472478
traceback. The exception type should be a class. Do not pass an invalid
473479
exception type or value. (Violating these rules will cause subtle problems
@@ -478,18 +484,17 @@ Querying the error indicator
478484
479485
.. note::
480486
481-
This function is normally only used by code that needs to save and restore the
482-
error indicator temporarily. Use :c:func:`PyErr_Fetch` to save the current
483-
error indicator.
484-
485-
.. deprecated:: 3.12
487+
This function is normally only used by legacy code that needs to
488+
save and restore the error indicator temporarily.
489+
Use :c:func:`PyErr_Fetch` to save the current error indicator.
486490
487491
488492
.. c:function:: void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
489493
490-
As of 3.12, this function is deprecated.
491-
Use :c:func:`PyErr_GetRaisedException` instead of :c:func:`PyErr_Fetch` to avoid
492-
any possible de-normalization.
494+
.. deprecated:: 3.12
495+
496+
Use :c:func:`PyErr_GetRaisedException` instead,
497+
to avoid any possible de-normalization.
493498
494499
Under certain circumstances, the values returned by :c:func:`PyErr_Fetch` below
495500
can be "unnormalized", meaning that ``*exc`` is a class object but ``*val`` is
@@ -507,8 +512,6 @@ Querying the error indicator
507512
PyException_SetTraceback(val, tb);
508513
}
509514
510-
.. deprecated:: 3.12
511-
512515
513516
.. c:function:: PyObject* PyErr_GetHandledException(void)
514517
@@ -756,14 +759,12 @@ Exception Objects
756759
757760
.. c:function:: PyObject* PyException_GetArgs(PyObject *ex)
758761
759-
Return args of the given exception as a new reference,
760-
as accessible from Python through :attr:`args`.
762+
Return :attr:`~BaseException.args` of exception *ex*.
761763
762764
763765
.. c:function:: void PyException_SetArgs(PyObject *ex, PyObject *args)
764766
765-
Set the args of the given exception,
766-
as accessible from Python through :attr:`args`.
767+
Set :attr:`~BaseException.args` of exception *ex* to *args*.
767768
768769
769770
.. _unicodeexceptions:

Doc/data/refcounts.dat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ PyEval_EvalFrameEx:int:throwflag::
839839
PyEval_MergeCompilerFlags:int:::
840840
PyEval_MergeCompilerFlags:PyCompilerFlags*:cf::
841841

842+
PyException_GetArgs:PyObject*::+1:
843+
842844
PyException_GetCause:PyObject*::+1:
843845
PyException_GetCause:PyObject*:ex:0:
844846

Doc/library/exceptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ The following exceptions are used mostly as base classes for other exceptions.
123123
try:
124124
...
125125
except SomeException:
126-
tb = sys.exc_info()[2]
126+
tb = sys.exception().__traceback__
127127
raise OtherException(...).with_traceback(tb)
128128

129129
.. method:: add_note(note)

Doc/library/functools.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ The :mod:`functools` module defines the following functions:
8686
The cached value can be cleared by deleting the attribute. This
8787
allows the *cached_property* method to run again.
8888

89+
The *cached_property* does not prevent a possible race condition in
90+
multi-threaded usage. The getter function could run more than once on the
91+
same instance, with the latest run setting the cached value. If the cached
92+
property is idempotent or otherwise not harmful to run more than once on an
93+
instance, this is fine. If synchronization is needed, implement the necessary
94+
locking inside the decorated getter function or around the cached property
95+
access.
96+
8997
Note, this decorator interferes with the operation of :pep:`412`
9098
key-sharing dictionaries. This means that instance dictionaries
9199
can take more space than usual.
@@ -110,6 +118,14 @@ The :mod:`functools` module defines the following functions:
110118
def stdev(self):
111119
return statistics.stdev(self._data)
112120

121+
122+
.. versionchanged:: 3.12
123+
Prior to Python 3.12, ``cached_property`` included an undocumented lock to
124+
ensure that in multi-threaded usage the getter function was guaranteed to
125+
run only once per instance. However, the lock was per-property, not
126+
per-instance, which could result in unacceptably high lock contention. In
127+
Python 3.12+ this locking is removed.
128+
113129
.. versionadded:: 3.8
114130

115131

Doc/library/queue.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module implements all the required locking semantics.
1515

1616
The module implements three types of queue, which differ only in the order in
1717
which the entries are retrieved. In a :abbr:`FIFO (first-in, first-out)`
18-
queue, the first tasks added are the first retrieved. In a
18+
queue, the first tasks added are the first retrieved. In a
1919
:abbr:`LIFO (last-in, first-out)` queue, the most recently added entry is
2020
the first retrieved (operating like a stack). With a priority queue,
2121
the entries are kept sorted (using the :mod:`heapq` module) and the
@@ -57,8 +57,8 @@ The :mod:`queue` module defines the following classes and exceptions:
5757
*maxsize* is less than or equal to zero, the queue size is infinite.
5858

5959
The lowest valued entries are retrieved first (the lowest valued entry is the
60-
one returned by ``sorted(list(entries))[0]``). A typical pattern for entries
61-
is a tuple in the form: ``(priority_number, data)``.
60+
one that would be returned by ``min(entries)``). A typical pattern for
61+
entries is a tuple in the form: ``(priority_number, data)``.
6262

6363
If the *data* elements are not comparable, the data can be wrapped in a class
6464
that ignores the data item and only compares the priority number::
@@ -127,8 +127,8 @@ provide the public methods described below.
127127

128128
.. method:: Queue.put(item, block=True, timeout=None)
129129

130-
Put *item* into the queue. If optional args *block* is true and *timeout* is
131-
``None`` (the default), block if necessary until a free slot is available. If
130+
Put *item* into the queue. If optional args *block* is true and *timeout* is
131+
``None`` (the default), block if necessary until a free slot is available. If
132132
*timeout* is a positive number, it blocks at most *timeout* seconds and raises
133133
the :exc:`Full` exception if no free slot was available within that time.
134134
Otherwise (*block* is false), put an item on the queue if a free slot is
@@ -143,7 +143,7 @@ provide the public methods described below.
143143

144144
.. method:: Queue.get(block=True, timeout=None)
145145

146-
Remove and return an item from the queue. If optional args *block* is true and
146+
Remove and return an item from the queue. If optional args *block* is true and
147147
*timeout* is ``None`` (the default), block if necessary until an item is available.
148148
If *timeout* is a positive number, it blocks at most *timeout* seconds and
149149
raises the :exc:`Empty` exception if no item was available within that time.
@@ -152,7 +152,7 @@ provide the public methods described below.
152152

153153
Prior to 3.0 on POSIX systems, and for all versions on Windows, if
154154
*block* is true and *timeout* is ``None``, this operation goes into
155-
an uninterruptible wait on an underlying lock. This means that no exceptions
155+
an uninterruptible wait on an underlying lock. This means that no exceptions
156156
can occur, and in particular a SIGINT will not trigger a :exc:`KeyboardInterrupt`.
157157

158158

@@ -184,7 +184,7 @@ fully processed by daemon consumer threads.
184184

185185
The count of unfinished tasks goes up whenever an item is added to the queue.
186186
The count goes down whenever a consumer thread calls :meth:`task_done` to
187-
indicate that the item was retrieved and all work on it is complete. When the
187+
indicate that the item was retrieved and all work on it is complete. When the
188188
count of unfinished tasks drops to zero, :meth:`join` unblocks.
189189

190190

@@ -227,7 +227,7 @@ SimpleQueue Objects
227227

228228
.. method:: SimpleQueue.empty()
229229

230-
Return ``True`` if the queue is empty, ``False`` otherwise. If empty()
230+
Return ``True`` if the queue is empty, ``False`` otherwise. If empty()
231231
returns ``False`` it doesn't guarantee that a subsequent call to get()
232232
will not block.
233233

Doc/library/stdtypes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ These are the Boolean operations, ordered by ascending priority:
8484
+-------------+---------------------------------+-------+
8585
| Operation | Result | Notes |
8686
+=============+=================================+=======+
87-
| ``x or y`` | if *x* is false, then *y*, else | \(1) |
88-
| | *x* | |
87+
| ``x or y`` | if *x* is true, then *x*, else | \(1) |
88+
| | *y* | |
8989
+-------------+---------------------------------+-------+
9090
| ``x and y`` | if *x* is false, then *x*, else | \(2) |
9191
| | *y* | |

Doc/library/struct.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ ordering::
371371
>>> from struct import *
372372
>>> pack(">bhl", 1, 2, 3)
373373
b'\x01\x00\x02\x00\x00\x00\x03'
374-
>>> unpack('>bhl', b'\x01\x00\x02\x00\x00\x00\x03'
374+
>>> unpack('>bhl', b'\x01\x00\x02\x00\x00\x00\x03')
375375
(1, 2, 3)
376376
>>> calcsize('>bhl')
377377
7

Doc/library/traceback.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ interpreter.
1616

1717
.. index:: object: traceback
1818

19-
The module uses traceback objects --- this is the object type that is stored in
20-
the :data:`sys.last_traceback` variable and returned as the third item from
21-
:func:`sys.exc_info`.
19+
The module uses traceback objects --- these are objects of type :class:`types.TracebackType`,
20+
which are assigned to the ``__traceback__`` field of :class:`BaseException` instances.
2221

2322
.. seealso::
2423

@@ -81,7 +80,7 @@ The module defines the following functions:
8180

8281
.. function:: print_exc(limit=None, file=None, chain=True)
8382

84-
This is a shorthand for ``print_exception(*sys.exc_info(), limit, file,
83+
This is a shorthand for ``print_exception(sys.exception(), limit, file,
8584
chain)``.
8685

8786

@@ -444,24 +443,24 @@ exception and traceback:
444443
try:
445444
lumberjack()
446445
except IndexError:
447-
exc_type, exc_value, exc_traceback = sys.exc_info()
446+
exc = sys.exception()
448447
print("*** print_tb:")
449-
traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
448+
traceback.print_tb(exc.__traceback__, limit=1, file=sys.stdout)
450449
print("*** print_exception:")
451-
traceback.print_exception(exc_value, limit=2, file=sys.stdout)
450+
traceback.print_exception(exc, limit=2, file=sys.stdout)
452451
print("*** print_exc:")
453452
traceback.print_exc(limit=2, file=sys.stdout)
454453
print("*** format_exc, first and last line:")
455454
formatted_lines = traceback.format_exc().splitlines()
456455
print(formatted_lines[0])
457456
print(formatted_lines[-1])
458457
print("*** format_exception:")
459-
print(repr(traceback.format_exception(exc_value)))
458+
print(repr(traceback.format_exception(exc)))
460459
print("*** extract_tb:")
461-
print(repr(traceback.extract_tb(exc_traceback)))
460+
print(repr(traceback.extract_tb(exc.__traceback__)))
462461
print("*** format_tb:")
463-
print(repr(traceback.format_tb(exc_traceback)))
464-
print("*** tb_lineno:", exc_traceback.tb_lineno)
462+
print(repr(traceback.format_tb(exc.__traceback__)))
463+
print("*** tb_lineno:", exc.__traceback__.tb_lineno)
465464

466465
The output for the example would look similar to this:
467466

Doc/library/turtle.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,9 @@ The demo scripts are:
24442444
| planet_and_moon| simulation of | compound shapes, |
24452445
| | gravitational system | :class:`Vec2D` |
24462446
+----------------+------------------------------+-----------------------+
2447+
| rosette | a pattern from the wikipedia | :func:`clone`, |
2448+
| | article on turtle graphics | :func:`undo` |
2449+
+----------------+------------------------------+-----------------------+
24472450
| round_dance | dancing turtles rotating | compound shapes, clone|
24482451
| | pairwise in opposite | shapesize, tilt, |
24492452
| | direction | get_shapepoly, update |
@@ -2457,9 +2460,6 @@ The demo scripts are:
24572460
| two_canvases | simple design | turtles on two |
24582461
| | | canvases |
24592462
+----------------+------------------------------+-----------------------+
2460-
| wikipedia | a pattern from the wikipedia | :func:`clone`, |
2461-
| | article on turtle graphics | :func:`undo` |
2462-
+----------------+------------------------------+-----------------------+
24632463
| yinyang | another elementary example | :func:`circle` |
24642464
+----------------+------------------------------+-----------------------+
24652465

Doc/library/types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Standard names are defined for the following types:
320320

321321
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
322322

323-
The type of traceback objects such as found in ``sys.exc_info()[2]``.
323+
The type of traceback objects such as found in ``sys.exception().__traceback__``.
324324

325325
See :ref:`the language reference <traceback-objects>` for details of the
326326
available attributes and operations, and guidance on creating tracebacks

0 commit comments

Comments
 (0)