Skip to content

Commit 6aa271c

Browse files
author
Erlend E. Aasland
authored
Merge branch 'main' into sqlite3-doc-cleanup-final-headings
2 parents 5eb1abc + 18b1782 commit 6aa271c

File tree

11 files changed

+101
-84
lines changed

11 files changed

+101
-84
lines changed

Doc/includes/sqlite3/rowclass.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

Doc/library/io.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,12 @@ Text I/O
10521052

10531053
The initial value of the buffer can be set by providing *initial_value*.
10541054
If newline translation is enabled, newlines will be encoded as if by
1055-
:meth:`~TextIOBase.write`. The stream is positioned at the start of
1056-
the buffer.
1055+
:meth:`~TextIOBase.write`. The stream is positioned at the start of the
1056+
buffer which emulates opening an existing file in a `w+` mode, making it
1057+
ready for an immediate write from the beginning or for a write that
1058+
would overwrite the initial value. To emulate opening a file in an `a+`
1059+
mode ready for appending, use `f.seek(0, io.SEEK_END)` to reposition the
1060+
stream at the end of the buffer.
10571061

10581062
The *newline* argument works like that of :class:`TextIOWrapper`,
10591063
except that when writing output to the stream, if *newline* is ``None``,

Doc/library/itertools.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,18 @@ which incur interpreter overhead.
800800
window.append(x)
801801
yield sum(map(operator.mul, kernel, window))
802802

803+
def polynomial_from_roots(roots):
804+
"""Compute a polynomial's coefficients from its roots.
805+
806+
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
807+
"""
808+
# polynomial_from_roots([5, -4, 3]) --> [1, -4, -17, 60]
809+
roots = list(map(operator.neg, roots))
810+
return [
811+
sum(map(math.prod, combinations(roots, k)))
812+
for k in range(len(roots) + 1)
813+
]
814+
803815
def flatten(list_of_lists):
804816
"Flatten one level of nesting"
805817
return chain.from_iterable(list_of_lists)
@@ -1137,6 +1149,13 @@ which incur interpreter overhead.
11371149
>>> list(convolve(data, [1, -2, 1]))
11381150
[20, 0, -36, 24, -20, 20, -20, -4, 16]
11391151

1152+
>>> polynomial_from_roots([5, -4, 3])
1153+
[1, -4, -17, 60]
1154+
>>> factored = lambda x: (x - 5) * (x + 4) * (x - 3)
1155+
>>> expanded = lambda x: x**3 -4*x**2 -17*x + 60
1156+
>>> all(factored(x) == expanded(x) for x in range(-10, 11))
1157+
True
1158+
11401159
>>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')]))
11411160
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
11421161

Doc/library/multiprocessing.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ will print to standard output ::
4545
[1, 4, 9]
4646

4747

48+
.. seealso::
49+
50+
:class:`concurrent.futures.ProcessPoolExecutor` offers a higher level interface
51+
to push tasks to a background process without blocking execution of the
52+
calling process. Compared to using the :class:`~multiprocessing.pool.Pool`
53+
interface directly, the :mod:`concurrent.futures` API more readily allows
54+
the submission of work to the underlying process pool to be separated from
55+
waiting for the results.
56+
57+
4858
The :class:`Process` class
4959
~~~~~~~~~~~~~~~~~~~~~~~~~~
5060

Doc/library/sqlite3.rst

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ inserted data and retrieved values from it in multiple ways.
207207
* :ref:`sqlite3-placeholders`
208208
* :ref:`sqlite3-adapters`
209209
* :ref:`sqlite3-converters`
210-
* :ref:`sqlite3-columns-by-name`
211210
* :ref:`sqlite3-connection-context-manager`
212211

213212
* :ref:`sqlite3-explanation` for in-depth background on transaction control.
@@ -1255,17 +1254,21 @@ Cursor objects
12551254
>>> cur.connection == con
12561255
True
12571256

1257+
.. The sqlite3.Row example used to be a how-to. It has now been incorporated
1258+
into the Row reference. We keep the anchor here in order not to break
1259+
existing links.
1260+
1261+
.. _sqlite3-columns-by-name:
12581262
.. _sqlite3-row-objects:
12591263

12601264
Row objects
12611265
^^^^^^^^^^^
12621266

12631267
.. class:: Row
12641268

1265-
A :class:`Row` instance serves as a highly optimized
1269+
A :class:`!Row` instance serves as a highly optimized
12661270
:attr:`~Connection.row_factory` for :class:`Connection` objects.
1267-
It tries to mimic a :class:`tuple` in most of its features,
1268-
and supports iteration, :func:`repr`, equality testing, :func:`len`,
1271+
It supports iteration, equality testing, :func:`len`,
12691272
and :term:`mapping` access by column name and index.
12701273

12711274
Two row objects compare equal if have equal columns and equal members.
@@ -1279,45 +1282,18 @@ Row objects
12791282
.. versionchanged:: 3.5
12801283
Added support of slicing.
12811284

1282-
Let's assume we initialize a table as in the example given above::
1285+
Example::
12831286

1284-
con = sqlite3.connect(":memory:")
1285-
cur = con.cursor()
1286-
cur.execute('''create table stocks
1287-
(date text, trans text, symbol text,
1288-
qty real, price real)''')
1289-
cur.execute("""insert into stocks
1290-
values ('2006-01-05','BUY','RHAT',100,35.14)""")
1291-
con.commit()
1292-
cur.close()
1293-
1294-
Now we plug :class:`Row` in::
1295-
1296-
>>> con.row_factory = sqlite3.Row
1297-
>>> cur = con.cursor()
1298-
>>> cur.execute('select * from stocks')
1299-
<sqlite3.Cursor object at 0x7f4e7dd8fa80>
1300-
>>> r = cur.fetchone()
1301-
>>> type(r)
1302-
<class 'sqlite3.Row'>
1303-
>>> tuple(r)
1304-
('2006-01-05', 'BUY', 'RHAT', 100.0, 35.14)
1305-
>>> len(r)
1306-
5
1307-
>>> r[2]
1308-
'RHAT'
1309-
>>> r.keys()
1310-
['date', 'trans', 'symbol', 'qty', 'price']
1311-
>>> r['qty']
1312-
100.0
1313-
>>> for member in r:
1314-
... print(member)
1315-
...
1316-
2006-01-05
1317-
BUY
1318-
RHAT
1319-
100.0
1320-
35.14
1287+
>>> con = sqlite3.connect(":memory:")
1288+
>>> con.row_factory = sqlite3.Row
1289+
>>> res = con.execute("SELECT 'Earth' AS name, 6378 AS radius")
1290+
>>> row = res.fetchone()
1291+
>>> row.keys()
1292+
['name', 'radius']
1293+
>>> row[0], row["name"] # Access by index and name.
1294+
('Earth', 'Earth')
1295+
>>> row["RADIUS"] # Column names are case-insensitive.
1296+
6378
13211297

13221298

13231299
.. _sqlite3-blob-objects:
@@ -1766,20 +1742,6 @@ directly using only a single call on the :class:`Connection` object.
17661742
.. literalinclude:: ../includes/sqlite3/shortcut_methods.py
17671743

17681744

1769-
.. _sqlite3-columns-by-name:
1770-
1771-
Hwo to access columns by name
1772-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1773-
1774-
One useful feature of the :mod:`!sqlite3` module is the built-in
1775-
:class:`sqlite3.Row` class designed to be used as a row factory.
1776-
1777-
Rows wrapped with this class can be accessed both by index (like tuples) and
1778-
case-insensitively by name:
1779-
1780-
.. literalinclude:: ../includes/sqlite3/rowclass.py
1781-
1782-
17831745
.. _sqlite3-connection-context-manager:
17841746

17851747
How to use a connection as a context manager

Doc/library/threading.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@
99
--------------
1010

1111
This module constructs higher-level threading interfaces on top of the lower
12-
level :mod:`_thread` module. See also the :mod:`queue` module.
12+
level :mod:`_thread` module.
1313

1414
.. versionchanged:: 3.7
1515
This module used to be optional, it is now always available.
1616

17+
.. seealso::
18+
19+
:class:`concurrent.futures.ThreadPoolExecutor` offers a higher level interface
20+
to push tasks to a background thread without blocking execution of the
21+
calling thread, while still being able to retrieve their results when needed.
22+
23+
:mod:`queue` provides a thread-safe interface for exchanging data between
24+
running threads.
25+
26+
:mod:`asyncio` offers an alternative approach to achieving task level
27+
concurrency without requiring the use of multiple operating system threads.
28+
1729
.. note::
1830

1931
In the Python 2.x series, this module contained ``camelCase`` names

Doc/tutorial/datastructures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ An example that uses most of the list methods::
106106
0
107107
>>> fruits.index('banana')
108108
3
109-
>>> fruits.index('banana', 4) # Find next banana starting a position 4
109+
>>> fruits.index('banana', 4) # Find next banana starting at position 4
110110
6
111111
>>> fruits.reverse()
112112
>>> fruits

Doc/using/configure.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ also be used to improve performance.
235235
.. cmdoption:: --enable-bolt
236236

237237
Enable usage of the `BOLT post-link binary optimizer
238-
<https://github.com/llvm/llvm-project/tree/main/bolt>` (disabled by
238+
<https://github.com/llvm/llvm-project/tree/main/bolt>`_ (disabled by
239239
default).
240240

241241
BOLT is part of the LLVM project but is not always included in their binary
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:c:func:`PyType_Ready` now initializes ``ht_cached_keys`` and performs
2+
additional checks to ensure that type objects are properly configured. This
3+
avoids crashes in 3rd party packages that don't use regular API to create
4+
new types.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improve discoverability of the higher level concurrent.futures module by
2+
providing clearer links from the lower level threading and multiprocessing
3+
modules.

0 commit comments

Comments
 (0)