Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged main into regmachine branch #50

Merged
merged 75 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
1cf3d78
Correct CVE-2020-10735 documentation (#100306)
ucodery Dec 18, 2022
532aa4e
gh-94912: Added marker for non-standard coroutine function detection …
carltongibson Dec 18, 2022
702a5bc
Docs: Don't upload CI artifacts (#100330)
hugovk Dec 19, 2022
797edb2
gh-89727: Fix os.walk RecursionError on deep trees (#99803)
jonburdo Dec 19, 2022
36a0b1d
gh-69929: re docs: Add more specific definition of \w (#92015)
slateny Dec 20, 2022
79ccc03
gh-89051: Add ssl.OP_LEGACY_SERVER_CONNECT (#93927)
graingert Dec 20, 2022
39dfbb2
gh-88211: Change lower-case and upper-case to match recommendations i…
tbwolfe Dec 20, 2022
a6331b6
gh-100348: Fix ref cycle in `asyncio._SelectorSocketTransport` with `…
rkojedzinszky Dec 20, 2022
d98ca81
gh-99925: Fix inconsistency in `json.dumps()` error messages (GH-99926)
fnesveda Dec 20, 2022
cb60b61
Clarify that every thread has its own default context in contextvars …
pablogsal Dec 20, 2022
44892d4
gh-99576: Fix cookiejar file that was not truncated for some classes …
sobolevn Dec 20, 2022
c18d831
gh-100188: Reduce misses in BINARY_SUBSCR_(LIST/TUPLE)_INT (#100189)
sweeneyde Dec 20, 2022
a2bb3b7
gh-99991: improve docs on str.encode and bytes.decode (#100198)
bizzyvinci Dec 21, 2022
c615286
gh-91081: Add note on WeakKeyDictionary behavior when deleting a repl…
slateny Dec 21, 2022
79311cb
gh-85267: Improvements to inspect.signature __text_signature__ handli…
hauntsaninja Dec 21, 2022
4994f24
GH-100363: Speed up `asyncio.get_running_loop` (#100364)
kumaraditya303 Dec 21, 2022
a7715cc
GH-100133: fix `asyncio` subprocess losing `stderr` and `stdout` outp…
kumaraditya303 Dec 21, 2022
12be23c
gh-100374: Fixed a bug in socket.getfqdn() (gh-100375)
MTAwsl Dec 21, 2022
b98d2d3
gh-100129: Add tests for pickling all builtin types and functions (GH…
serhiy-storchaka Dec 21, 2022
e0b4d96
Remove unused variable from `dis._find_imports` (#100396)
sobolevn Dec 21, 2022
d713c54
gh-78878: Fix crash when creating an instance of `_ctypes.CField` (#1…
shihai1991 Dec 21, 2022
bbf4a66
GH-69564: Clarify use of octal format of mode argument in help(os.chm…
amaajemyfren Dec 21, 2022
3c033a2
GH-99554: Pack location tables more effectively (GH-99556)
brandtbucher Dec 22, 2022
6898157
Correct typo in typing.py (#100423)
david-why Dec 22, 2022
2b82c36
gh-99761: Add `_PyLong_IsPositiveSingleDigit` function to check for s…
eendebakpt Dec 22, 2022
a021612
GH-99770: Make the correct call specialization fail kind show up in t…
penguin-wwy Dec 22, 2022
aa878f0
gh-78997: fix bad rebase of moved test file (#100424)
eli-schwartz Dec 22, 2022
4cc63e0
gh-100344: Add C implementation for `asyncio.current_task` (#100345)
itamaro Dec 22, 2022
09edde9
GH-99554: Trim trailing whitespace (GH-100435)
brandtbucher Dec 22, 2022
9cdb642
gh-85432: Harmonise parameter names between C and pure-Python impleme…
AlexWaygood Dec 22, 2022
ad23da0
gh-57762: fix misleading tkinter.Tk docstring (#98837)
hauntsaninja Dec 22, 2022
f3db68e
gh-48496: Added example and link to faq for UnboundLocalError in refe…
slateny Dec 22, 2022
73c08ee
Fix typo in 3.12 What's New (#100449)
hauntsaninja Dec 23, 2022
84bc6a4
gh-76963: PEP3118 itemsize of an empty ctypes array should not be 0 (…
eric-wieser Dec 23, 2022
2659036
GH-100459: fix copy-paste errors in specialization stats (GH-100460)
iritkatriel Dec 23, 2022
88d565f
gh-99110: Initialize `frame->previous` in init_frame to fix segmentat…
byllyfish Dec 23, 2022
49f6ff7
gh-98712: Clarify "readonly bytes-like object" semantics in C arg-par…
encukou Dec 23, 2022
7fc7909
gh-92216: improve performance of `hasattr` for type objects (GH-99979)
eendebakpt Dec 23, 2022
c3c7848
gh-100288: Specialise LOAD_ATTR_METHOD for managed dictionaries (GH-1…
Fidget-Spinner Dec 23, 2022
36d3583
Revert "gh-100288: Specialise LOAD_ATTR_METHOD for managed dictionari…
Fidget-Spinner Dec 23, 2022
a98d9ea
gh-94155: Reduce hash collisions for code objects (#100183)
sweeneyde Dec 23, 2022
c5726b7
gh-83076: 3.8x speed improvement in (Async)Mock instantiation (#100252)
carljm Dec 23, 2022
745545b
gh-99482: remove `jython` compatibility parts from stdlib and tests (…
sobolevn Dec 23, 2022
1ecfd1e
bpo-40447: accept all path-like objects in compileall.compile_file (#…
FFY00 Dec 23, 2022
5d84966
GH-100425: Improve accuracy of builtin sum() for float inputs (GH-100…
rhettinger Dec 23, 2022
a68e585
gh-68320, gh-88302 - Allow for private `pathlib.Path` subclassing (GH…
barneygale Dec 23, 2022
474220e
gh-99947: Ensure unreported errors are chained for SystemError during…
seberg Dec 23, 2022
f89de67
Add "strict" to dotproduct(). Add docstring. Factor-out common code. …
rhettinger Dec 23, 2022
7ca45e5
gh-94808: improve test coverage of number formatting (#99472)
sobolevn Dec 24, 2022
a23cb72
gh-100454: Start running SSL tests with OpenSSL 3.1.0-beta1 (#100456)
illia-v Dec 24, 2022
3e46f9f
gh-100268: Add is_integer method to int (#100439)
hauntsaninja Dec 24, 2022
0f64206
gh-77771: Add enterabs example in sched (#92716)
slateny Dec 24, 2022
c122390
GH-91166: Implement zero copy writes for `SelectorSocketTransport` in…
kumaraditya303 Dec 24, 2022
2eea959
GH-91166: Implement zero copy writes for `SelectorSocketTransport` in…
kumaraditya303 Dec 24, 2022
0769f95
Misc Itertools recipe tweaks (GH-100493)
rhettinger Dec 24, 2022
bdfb694
gh-100357: Convert several functions in `bltinsmodule` to AC (#100358)
sobolevn Dec 24, 2022
c6dac12
Remove wrong comment about `repr` in `test_unicode` (#100495)
sobolevn Dec 24, 2022
00afa50
gh-99908: Tutorial: Modernize the 'data-record class' example (#100499)
JosephSBoyle Dec 24, 2022
46e6a28
gh-100474: Fix handling of dirs named index.html in http.server (GH-1…
Fraetor Dec 24, 2022
e4b43eb
gh-100287: Fix unittest.mock.seal with AsyncMock (#100496)
hauntsaninja Dec 24, 2022
f5b7b19
gh-99535: Add test for inheritance of annotations and update document…
MonadChains Dec 24, 2022
2e1a9ce
gh-100428: Make float documentation more accurate (#100437)
hauntsaninja Dec 24, 2022
efccd04
[Minor PR] Quotes in documentation changed into code blocks (#99536)
bartbroere Dec 24, 2022
046cbc2
gh-100472: Fix docs claim that compileall parameters could be bytes (…
hauntsaninja Dec 24, 2022
b9aa14a
gh-100519: simplification to `eff_request_host` in cookiejar.py (#99588)
glyph Dec 25, 2022
dbc1e69
gh-99308: Clarify re docs for byte pattern group names (#99311)
Kentzo Dec 25, 2022
ad3c99e
gh-92446: Improve argparse choices docs; revert bad change to lzma do…
yourlefthandman Dec 26, 2022
3ccc98f
Fix name of removed `inspect.Signature.from_builtin` method in 3.11.0…
Jackenmen Dec 26, 2022
199507b
gh-100520: Fix `rst` markup in `configparser` docstrings (#100524)
sobolevn Dec 26, 2022
ce39aaf
gh-99509: Add `__class_getitem__` to `multiprocessing.queues.Queue` (…
sobolevn Dec 27, 2022
b3da698
gh-94603: micro optimize list.pop (gh-94604)
eendebakpt Dec 27, 2022
b0ea289
Remove `NoneType` redefinition from `clinic.py` (#100551)
sobolevn Dec 27, 2022
3dc48da
gh-100553: Improve accuracy of sqlite3.Row iter test (#100555)
sobolevn Dec 28, 2022
08e5594
GH-98831: Modernize a ton of simpler instructions (#100545)
gvanrossum Dec 28, 2022
b8b8250
Merge remote-tracking branch 'origin/main' into regmachine
gvanrossum Dec 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ jobs:
strategy:
fail-fast: false
matrix:
openssl_ver: [1.1.1s, 3.0.7]
openssl_ver: [1.1.1s, 3.0.7, 3.1.0-beta1]
env:
OPENSSL_VER: ${{ matrix.openssl_ver }}
MULTISSL_DIR: ${{ github.workspace }}/multissl
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,8 @@ jobs:
run: make -C Doc/ venv
- name: 'Check documentation'
run: make -C Doc/ check
- name: 'Upload NEWS'
uses: actions/upload-artifact@v3
with:
name: NEWS
path: Doc/build/NEWS
- name: 'Build HTML documentation'
run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html
- name: 'Upload docs'
uses: actions/upload-artifact@v3
with:
name: doc-html
path: Doc/build/html

# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
Expand Down
54 changes: 35 additions & 19 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,39 @@ These formats allow accessing an object as a contiguous chunk of memory.
You don't have to provide raw storage for the returned unicode or bytes
area.

In general, when a format sets a pointer to a buffer, the buffer is
managed by the corresponding Python object, and the buffer shares
the lifetime of this object. You won't have to release any memory yourself.
The only exceptions are ``es``, ``es#``, ``et`` and ``et#``.

However, when a :c:type:`Py_buffer` structure gets filled, the underlying
buffer is locked so that the caller can subsequently use the buffer even
inside a :c:type:`Py_BEGIN_ALLOW_THREADS` block without the risk of mutable data
being resized or destroyed. As a result, **you have to call**
:c:func:`PyBuffer_Release` after you have finished processing the data (or
in any early abort case).

Unless otherwise stated, buffers are not NUL-terminated.

Some formats require a read-only :term:`bytes-like object`, and set a
pointer instead of a buffer structure. They work by checking that
the object's :c:member:`PyBufferProcs.bf_releasebuffer` field is ``NULL``,
which disallows mutable objects such as :class:`bytearray`.
There are three ways strings and buffers can be converted to C:

* Formats such as ``y*`` and ``s*`` fill a :c:type:`Py_buffer` structure.
This locks the underlying buffer so that the caller can subsequently use
the buffer even inside a :c:type:`Py_BEGIN_ALLOW_THREADS`
block without the risk of mutable data being resized or destroyed.
As a result, **you have to call** :c:func:`PyBuffer_Release` after you have
finished processing the data (or in any early abort case).

* The ``es``, ``es#``, ``et`` and ``et#`` formats allocate the result buffer.
**You have to call** :c:func:`PyMem_Free` after you have finished
processing the data (or in any early abort case).

* .. _c-arg-borrowed-buffer:

Other formats take a :class:`str` or a read-only :term:`bytes-like object`,
such as :class:`bytes`, and provide a ``const char *`` pointer to
its buffer.
In this case the buffer is "borrowed": it is managed by the corresponding
Python object, and shares the lifetime of this object.
You won't have to release any memory yourself.

To ensure that the underlying buffer may be safely borrowed, the object's
:c:member:`PyBufferProcs.bf_releasebuffer` field must be ``NULL``.
This disallows common mutable objects such as :class:`bytearray`,
but also some read-only objects such as :class:`memoryview` of
:class:`bytes`.

Besides this ``bf_releasebuffer`` requirement, there is no check to verify
whether the input object is immutable (e.g. whether it would honor a request
for a writable buffer, or whether another thread can mutate the data).

.. note::

Expand Down Expand Up @@ -89,7 +104,7 @@ which disallows mutable objects such as :class:`bytearray`.
Unicode objects are converted to C strings using ``'utf-8'`` encoding.

``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, :c:type:`Py_ssize_t`]
Like ``s*``, except that it doesn't accept mutable objects.
Like ``s*``, except that it provides a :ref:`borrowed buffer <c-arg-borrowed-buffer>`.
The result is stored into two C variables,
the first one a pointer to a C string, the second one its length.
The string may contain embedded null bytes. Unicode objects are converted
Expand All @@ -108,8 +123,9 @@ which disallows mutable objects such as :class:`bytearray`.
pointer is set to ``NULL``.

``y`` (read-only :term:`bytes-like object`) [const char \*]
This format converts a bytes-like object to a C pointer to a character
string; it does not accept Unicode objects. The bytes buffer must not
This format converts a bytes-like object to a C pointer to a
:ref:`borrowed <c-arg-borrowed-buffer>` character string;
it does not accept Unicode objects. The bytes buffer must not
contain embedded null bytes; if it does, a :exc:`ValueError`
exception is raised.

Expand Down
2 changes: 2 additions & 0 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Yes. The coding style required for standard library modules is documented as
Core Language
=============

.. _faq-unboundlocalerror:

Why am I getting an UnboundLocalError when the variable has a value?
--------------------------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions Doc/howto/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Accessing The Annotations Dict Of An Object In Python 3.10 And Newer
newer is to call :func:`getattr` with three arguments,
for example ``getattr(o, '__annotations__', None)``.

Before Python 3.10, accessing ``__annotations__`` on a class that
defines no annotations but that has a parent class with
annotations would return the parent's ``__annotations__``.
In Python 3.10 and newer, the child class's annotations
will be an empty dict instead.


Accessing The Annotations Dict Of An Object In Python 3.9 And Older
===================================================================
Expand Down
12 changes: 6 additions & 6 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ The add_argument() method

* type_ - The type to which the command-line argument should be converted.

* choices_ - A container of the allowable values for the argument.
* choices_ - A sequence of the allowable values for the argument.

* required_ - Whether or not the command-line option may be omitted
(optionals only).
Expand Down Expand Up @@ -1209,7 +1209,7 @@ choices
^^^^^^^

Some command-line arguments should be selected from a restricted set of values.
These can be handled by passing a container object as the *choices* keyword
These can be handled by passing a sequence object as the *choices* keyword
argument to :meth:`~ArgumentParser.add_argument`. When the command line is
parsed, argument values will be checked, and an error message will be displayed
if the argument was not one of the acceptable values::
Expand All @@ -1223,9 +1223,9 @@ if the argument was not one of the acceptable values::
game.py: error: argument move: invalid choice: 'fire' (choose from 'rock',
'paper', 'scissors')

Note that inclusion in the *choices* container is checked after any type_
Note that inclusion in the *choices* sequence is checked after any type_
conversions have been performed, so the type of the objects in the *choices*
container should match the type_ specified::
sequence should match the type_ specified::

>>> parser = argparse.ArgumentParser(prog='doors.py')
>>> parser.add_argument('door', type=int, choices=range(1, 4))
Expand All @@ -1235,8 +1235,8 @@ container should match the type_ specified::
usage: doors.py [-h] {1,2,3}
doors.py: error: argument door: invalid choice: 4 (choose from 1, 2, 3)

Any container can be passed as the *choices* value, so :class:`list` objects,
:class:`set` objects, and custom containers are all supported.
Any sequence can be passed as the *choices* value, so :class:`list` objects,
:class:`tuple` objects, and custom sequences are all supported.

Use of :class:`enum.Enum` is not recommended because it is difficult to
control its appearance in usage, help, and error messages.
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/compileall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Public functions

The *stripdir*, *prependdir* and *limit_sl_dest* arguments correspond to
the ``-s``, ``-p`` and ``-e`` options described above.
They may be specified as ``str``, ``bytes`` or :py:class:`os.PathLike`.
They may be specified as ``str`` or :py:class:`os.PathLike`.

If *hardlink_dupes* is true and two ``.pyc`` files with different optimization
level have the same content, use hard links to consolidate duplicate files.
Expand Down Expand Up @@ -269,7 +269,7 @@ Public functions

The *stripdir*, *prependdir* and *limit_sl_dest* arguments correspond to
the ``-s``, ``-p`` and ``-e`` options described above.
They may be specified as ``str``, ``bytes`` or :py:class:`os.PathLike`.
They may be specified as ``str`` or :py:class:`os.PathLike`.

If *hardlink_dupes* is true and two ``.pyc`` files with different optimization
level have the same content, use hard links to consolidate duplicate files.
Expand Down
5 changes: 5 additions & 0 deletions Doc/library/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ Manual Context Management
To get a copy of the current context use the
:func:`~contextvars.copy_context` function.

Every thread will have a different top-level :class:`~contextvars.Context`
object. This means that a :class:`ContextVar` object behaves in a similar
fashion to :func:`threading.local()` when values are assigned in different
threads.

Context implements the :class:`collections.abc.Mapping` interface.

.. method:: run(callable, *args, **kwargs)
Expand Down
23 changes: 15 additions & 8 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -650,20 +650,23 @@ are always available. They are listed here in alphabetical order.
sign may be ``'+'`` or ``'-'``; a ``'+'`` sign has no effect on the value
produced. The argument may also be a string representing a NaN
(not-a-number), or positive or negative infinity. More precisely, the
input must conform to the following grammar after leading and trailing
whitespace characters are removed:
input must conform to the ``floatvalue`` production rule in the following
grammar, after leading and trailing whitespace characters are removed:

.. productionlist:: float
sign: "+" | "-"
infinity: "Infinity" | "inf"
nan: "nan"
numeric_value: `floatnumber` | `infinity` | `nan`
numeric_string: [`sign`] `numeric_value`
digitpart: `digit` (["_"] `digit`)*
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
exponent: ("e" | "E") ["+" | "-"] `digitpart`
floatnumber: number [`exponent`]
floatvalue: [`sign`] (`floatnumber` | `infinity` | `nan`)

Here ``floatnumber`` is the form of a Python floating-point literal,
described in :ref:`floating`. Case is not significant, so, for example,
"inf", "Inf", "INFINITY", and "iNfINity" are all acceptable spellings for
positive infinity.
Here ``digit`` is a Unicode decimal digit (character in the Unicode general
category ``Nd``). Case is not significant, so, for example, "inf", "Inf",
"INFINITY", and "iNfINity" are all acceptable spellings for positive
infinity.

Otherwise, if the argument is an integer or a floating point number, a
floating point number with the same value (within Python's floating point
Expand Down Expand Up @@ -1733,6 +1736,10 @@ are always available. They are listed here in alphabetical order.
.. versionchanged:: 3.8
The *start* parameter can be specified as a keyword argument.

.. versionchanged:: 3.12 Summation of floats switched to an algorithm
that gives higher accuracy on most builds.


.. class:: super()
super(type, object_or_type=None)

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/imaplib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ IMAP4 Objects
-------------

All IMAP4rev1 commands are represented by methods of the same name, either
upper-case or lower-case.
uppercase or lowercase.

All arguments to commands are converted to strings, except for ``AUTHENTICATE``,
and the last argument to ``APPEND`` which is passed as an IMAP4 literal. If
Expand Down
25 changes: 23 additions & 2 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,36 @@ attributes (see :ref:`import-mod-attrs` for module attributes):

.. function:: iscoroutinefunction(object)

Return ``True`` if the object is a :term:`coroutine function`
(a function defined with an :keyword:`async def` syntax).
Return ``True`` if the object is a :term:`coroutine function` (a function
defined with an :keyword:`async def` syntax), a :func:`functools.partial`
wrapping a :term:`coroutine function`, or a sync function marked with
:func:`markcoroutinefunction`.

.. versionadded:: 3.5

.. versionchanged:: 3.8
Functions wrapped in :func:`functools.partial` now return ``True`` if the
wrapped function is a :term:`coroutine function`.

.. versionchanged:: 3.12
Sync functions marked with :func:`markcoroutinefunction` now return
``True``.


.. function:: markcoroutinefunction(func)

Decorator to mark a callable as a :term:`coroutine function` if it would not
otherwise be detected by :func:`iscoroutinefunction`.

This may be of use for sync functions that return a :term:`coroutine`, if
the function is passed to an API that requires :func:`iscoroutinefunction`.

When possible, using an :keyword:`async def` function is preferred. Also
acceptable is calling the function and testing the return with
:func:`iscoroutine`.

.. versionadded:: 3.12


.. function:: iscoroutine(object)

Expand Down
59 changes: 52 additions & 7 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,11 @@ which incur interpreter overhead.

.. testcode::

import collections
import math
import operator
import random

def take(n, iterable):
"Return first n items of the iterable as a list"
return list(islice(iterable, n))
Expand Down Expand Up @@ -834,7 +839,8 @@ which incur interpreter overhead.
return chain.from_iterable(repeat(tuple(iterable), n))

def dotproduct(vec1, vec2):
return sum(map(operator.mul, vec1, vec2))
"Compute a sum of products."
return sum(starmap(operator.mul, zip(vec1, vec2, strict=True)))

def convolve(signal, kernel):
# See: https://betterexplained.com/articles/intuitive-convolution/
Expand All @@ -846,7 +852,7 @@ which incur interpreter overhead.
window = collections.deque([0], maxlen=n) * n
for x in chain(signal, repeat(0, n-1)):
window.append(x)
yield sum(map(operator.mul, kernel, window))
yield dotproduct(kernel, window)

def polynomial_from_roots(roots):
"""Compute a polynomial's coefficients from its roots.
Expand Down Expand Up @@ -891,6 +897,21 @@ which incur interpreter overhead.
data[2] = 1
return iter_index(data, 1) if n > 2 else iter([])

def factor(n):
"Prime factors of n."
# factor(97) --> 97
# factor(98) --> 2 7 7
# factor(99) --> 3 3 11
for prime in sieve(n+1):
while True:
quotient, remainder = divmod(n, prime)
if remainder:
break
yield prime
n = quotient
if n == 1:
return

def flatten(list_of_lists):
"Flatten one level of nesting"
return chain.from_iterable(list_of_lists)
Expand Down Expand Up @@ -1133,11 +1154,6 @@ which incur interpreter overhead.

Now, we test all of the itertool recipes

>>> import operator
>>> import collections
>>> import math
>>> import random

>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Expand Down Expand Up @@ -1250,6 +1266,35 @@ which incur interpreter overhead.
>>> set(sieve(10_000)).isdisjoint(carmichael)
True

list(factor(0))
[]
list(factor(1))
[]
list(factor(2))
[2]
list(factor(3))
[3]
list(factor(4))
[2, 2]
list(factor(5))
[5]
list(factor(6))
[2, 3]
list(factor(7))
[7]
list(factor(8))
[2, 2, 2]
list(factor(9))
[3, 3]
list(factor(10))
[2, 5]
all(math.prod(factor(n)) == n for n in range(1, 1000))
True
all(set(factor(n)) <= set(sieve(n+1)) for n in range(1, 1000))
True
all(list(factor(n)) == sorted(factor(n)) for n in range(1, 1000))
True

>>> list(flatten([('a', 'b'), (), ('c', 'd', 'e'), ('f',), ('g', 'h', 'i')]))
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/lzma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Compressing and decompressing data in memory
This format is more limited than ``.xz`` -- it does not support integrity
checks or multiple filters.

* :const:`FORMAT_RAW`: A raw data stream, not using sequences format.
* :const:`FORMAT_RAW`: A raw data stream, not using any container format.
This format specifier does not support integrity checks, and requires that
you always specify a custom filter chain (for both compression and
decompression). Additionally, data compressed in this manner cannot be
Expand Down
Loading