summaryrefslogtreecommitdiff
path: root/Doc/library
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/collections.abc.rst3
-rw-r--r--Doc/library/datetime.rst10
-rw-r--r--Doc/library/enum.rst12
-rw-r--r--Doc/library/exceptions.rst23
-rw-r--r--Doc/library/random.rst11
-rw-r--r--Doc/library/typing.rst2
6 files changed, 50 insertions, 11 deletions
diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst
index 0abc87f919..2c941b4774 100644
--- a/Doc/library/collections.abc.rst
+++ b/Doc/library/collections.abc.rst
@@ -104,6 +104,9 @@ example, knowing that a class supplies ``__getitem__``, ``__len__``, and
``__iter__`` is insufficient for distinguishing a :class:`Sequence` from
a :class:`Mapping`.
+.. versionadded:: 3.9
+ These abstract classes now support ``[]``. See :ref:`types-genericalias`
+ and :pep:`585`.
.. _collections-abstract-base-classes:
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 196aa84473..0f8b70cded 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -27,6 +27,9 @@ on efficient attribute extraction for output formatting and manipulation.
Module :mod:`time`
Time access and conversions.
+ Module :mod:`zoneinfo`
+ Concrete time zones representing the IANA time zone database.
+
Package `dateutil <https://dateutil.readthedocs.io/en/stable/>`_
Third-party library with expanded time zone and parsing support.
@@ -2174,14 +2177,13 @@ only EST (fixed offset -5 hours), or only EDT (fixed offset -4 hours)).
.. seealso::
- `dateutil.tz <https://dateutil.readthedocs.io/en/stable/tz.html>`_
+ :mod:`zoneinfo`
The :mod:`datetime` module has a basic :class:`timezone` class (for
handling arbitrary fixed offsets from UTC) and its :attr:`timezone.utc`
attribute (a UTC timezone instance).
- *dateutil.tz* library brings the *IANA timezone database*
- (also known as the Olson database) to Python, and its usage is
- recommended.
+ ``zoneinfo`` brings the *IANA timezone database* (also known as the Olson
+ database) to Python, and its usage is recommended.
`IANA timezone database <https://www.iana.org/time-zones>`_
The Time Zone Database (often called tz, tzdata or zoneinfo) contains code
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index 2d80a52193..eb5ffd0c5d 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -1127,7 +1127,7 @@ _Private__names
:ref:`Private names <private-name-mangling>` will be normal attributes in Python
3.11 instead of either an error or a member (depending on if the name ends with
-an underscore). Using these names in 3.9 will issue a :exc:`DeprecationWarning`.
+an underscore). Using these names in 3.10 will issue a :exc:`DeprecationWarning`.
``Enum`` member type
@@ -1150,6 +1150,10 @@ all-uppercase names for members)::
>>> FieldTypes.size.value
2
+.. note::
+
+ This behavior is deprecated and will be removed in 3.12.
+
.. versionchanged:: 3.5
@@ -1200,3 +1204,9 @@ all named flags and all named combinations of flags that are in the value::
>>> Color(7) # not named combination
<Color.CYAN|MAGENTA|BLUE|YELLOW|GREEN|RED: 7>
+.. note::
+
+ In 3.11 unnamed combinations of flags will only produce the canonical flag
+ members (aka single-value flags). So ``Color(7)`` will produce something
+ like ``<Color.BLUE|GREEN|RED: 7>``.
+
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index 1a883ba19a..f8a692e812 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -34,6 +34,10 @@ class or one of its subclasses, and not from :exc:`BaseException`. More
information on defining exceptions is available in the Python Tutorial under
:ref:`tut-userexceptions`.
+
+Exception context
+-----------------
+
When raising (or re-raising) an exception in an :keyword:`except` or
:keyword:`finally` clause
:attr:`__context__` is automatically set to the last exception caught; if the
@@ -67,6 +71,25 @@ exceptions so that the final line of the traceback always shows the last
exception that was raised.
+Inheriting from built-in exceptions
+-----------------------------------
+
+User code can create subclasses that inherit from an exception type.
+It's recommended to only subclass one exception type at a time to avoid
+any possible conflicts between how the bases handle the ``args``
+attribute, as well as due to possible memory layout incompatibilities.
+
+.. impl-detail::
+
+ Most built-in exceptions are implemented in C for efficiency, see:
+ :source:`Objects/exceptions.c`. Some have custom memory layouts
+ which makes it impossible to create a subclass that inherits from
+ multiple exception types. The memory layout of a type is an implementation
+ detail and might change between Python versions, leading to new
+ conflicts in the future. Therefore, it's recommended to avoid
+ subclassing multiple exception types altogether.
+
+
Base classes
------------
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index e924127d8b..b9c33af59c 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -512,7 +512,7 @@ between the effects of a drug versus a placebo::
Simulation of arrival times and service deliveries for a multiserver queue::
- from heapq import heappush, heappop
+ from heapq import heapify, heapreplace
from random import expovariate, gauss
from statistics import mean, quantiles
@@ -524,14 +524,15 @@ Simulation of arrival times and service deliveries for a multiserver queue::
waits = []
arrival_time = 0.0
servers = [0.0] * num_servers # time when each server becomes available
- for i in range(100_000):
+ heapify(servers)
+ for i in range(1_000_000):
arrival_time += expovariate(1.0 / average_arrival_interval)
- next_server_available = heappop(servers)
+ next_server_available = servers[0]
wait = max(0.0, next_server_available - arrival_time)
waits.append(wait)
- service_duration = gauss(average_service_time, stdev_service_time)
+ service_duration = max(0.0, gauss(average_service_time, stdev_service_time))
service_completed = arrival_time + wait + service_duration
- heappush(servers, service_completed)
+ heapreplace(servers, service_completed)
print(f'Mean wait: {mean(waits):.1f} Max wait: {max(waits):.1f}')
print('Quartiles:', [round(q, 1) for q in quantiles(waits)])
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 13760c1921..c402c73b48 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -19,7 +19,7 @@
This module provides runtime support for type hints as specified by
:pep:`484`, :pep:`526`, :pep:`544`, :pep:`586`, :pep:`589`, :pep:`591`,
-:pep:`612` and :pep:`613`.
+:pep:`593`, :pep:`612`, :pep:`613` and :pep:`647`.
The most fundamental support consists of the types :data:`Any`, :data:`Union`,
:data:`Tuple`, :data:`Callable`, :class:`TypeVar`, and
:class:`Generic`. For full specification please see :pep:`484`. For