Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-104090-fix-leaked-semaphors-on-test…
Browse files Browse the repository at this point in the history
…_concurrent_futures-v2
  • Loading branch information
bityob committed Jul 17, 2023
2 parents 1de022d + 036bb73 commit 48bea84
Show file tree
Hide file tree
Showing 20 changed files with 385 additions and 282 deletions.
10 changes: 5 additions & 5 deletions Doc/includes/email-alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

# Create the base text message.
msg = EmailMessage()
msg['Subject'] = "Ayons asperges pour le déjeuner"
msg['Subject'] = "Pourquoi pas des asperges pour ce midi ?"
msg['From'] = Address("Pepé Le Pew", "pepe", "example.com")
msg['To'] = (Address("Penelope Pussycat", "penelope", "example.com"),
Address("Fabrette Pussycat", "fabrette", "example.com"))
msg.set_content("""\
Salut!
Cela ressemble à un excellent recipie[1] déjeuner.
Cette recette [1] sera sûrement un très bon repas.
[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
Expand All @@ -31,10 +31,10 @@
<head></head>
<body>
<p>Salut!</p>
<p>Cela ressemble à un excellent
<p>Cette
<a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718">
recipie
</a> déjeuner.
recette
</a> sera sûrement un très bon repas.
</p>
<img src="cid:{asparagus_cid}" />
</body>
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/devmode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setting the :envvar:`PYTHONDEVMODE` environment variable to ``1``.
See also :ref:`Python debug build <debug-build>`.

Effects of the Python Development Mode
======================================
--------------------------------------

Enabling the Python Development Mode is similar to the following command, but
with additional effects described below::
Expand Down Expand Up @@ -107,7 +107,7 @@ value can be read from :data:`sys.flags.dev_mode <sys.flags>`.


ResourceWarning Example
=======================
-----------------------

Example of a script counting the number of lines of the text file specified in
the command line::
Expand Down Expand Up @@ -171,7 +171,7 @@ application more deterministic and more reliable.


Bad file descriptor error example
=================================
---------------------------------

Script displaying the first line of itself::

Expand Down
4 changes: 2 additions & 2 deletions Doc/library/email.examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Up to the prompt, the output from the above is:
To: Penelope Pussycat <[email protected]>, Fabrette Pussycat <[email protected]>
From: Pepé Le Pew <[email protected]>
Subject: Ayons asperges pour le déjeuner
Subject: Pourquoi pas des asperges pour ce midi ?
Salut!
Cela ressemble à un excellent recipie[1] déjeuner.
Cette recette [1] sera sûrement un très bon repas.
.. rubric:: Footnotes
Expand Down
11 changes: 8 additions & 3 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,10 @@ The following recipes have a more mathematical flavor:
# factor(1_000_000_000_000_403) --> 1000000000000403
for prime in sieve(math.isqrt(n) + 1):
while True:
quotient, remainder = divmod(n, prime)
if remainder:
if n % prime:
break
yield prime
n = quotient
n //= prime
if n == 1:
return
if n > 1:
Expand Down Expand Up @@ -1354,6 +1353,12 @@ The following recipes have a more mathematical flavor:
>>> set(sieve(10_000)).isdisjoint(carmichael)
True

>>> list(factor(99)) # Code example 1
[3, 3, 11]
>>> list(factor(1_000_000_000_000_007)) # Code example 2
[47, 59, 360620266859]
>>> list(factor(1_000_000_000_000_403)) # Code example 3
[1000000000000403]
>>> list(factor(0))
[]
>>> list(factor(1))
Expand Down
8 changes: 7 additions & 1 deletion Doc/tutorial/controlflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,13 @@ Dotted names (like ``foo.bar``), attribute names (the ``x=`` and ``y=`` above) o
(recognized by the "(...)" next to them like ``Point`` above) are never assigned to.

Patterns can be arbitrarily nested. For example, if we have a short
list of points, we could match it like this::
list of Points, with ``__match_args__`` added, we could match it like this::

class Point:
__match_args__ = ('x', 'y')
def __init__(self, x, y):
self.x = x
self.y = y

match points:
case []:
Expand Down
10 changes: 5 additions & 5 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Lib/contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AbstractContextManager(abc.ABC):

__class_getitem__ = classmethod(GenericAlias)

__slots__ = ()

def __enter__(self):
"""Return `self` upon entering the runtime context."""
return self
Expand All @@ -42,6 +44,8 @@ class AbstractAsyncContextManager(abc.ABC):

__class_getitem__ = classmethod(GenericAlias)

__slots__ = ()

async def __aenter__(self):
"""Return `self` upon entering the runtime context."""
return self
Expand Down
26 changes: 7 additions & 19 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@

__all__ = ["cmp_op", "hasarg", "hasconst", "hasname", "hasjrel", "hasjabs",
"haslocal", "hascompare", "hasfree", "hasexc", "opname", "opmap",
"HAVE_ARGUMENT", "EXTENDED_ARG"]

# It's a chicken-and-egg I'm afraid:
# We're imported before _opcode's made.
# With exception unheeded
# (stack_effect is not needed)
# Both our chickens and eggs are allayed.
# --Larry Hastings, 2013/11/23

try:
from _opcode import stack_effect
__all__.append('stack_effect')
except ImportError:
pass

# _opcode_metadata may not be ready during early stages of the build
try:
"stack_effect", "HAVE_ARGUMENT", "EXTENDED_ARG"]

from _opcode import stack_effect

import sys
# The build uses older versions of Python which do not have _opcode_metadata
if sys.version_info[:2] >= (3, 13):
from _opcode_metadata import _specializations, _specialized_instructions
except ModuleNotFoundError:
pass

cmp_op = ('<', '<=', '==', '!=', '>', '>=')

Expand Down
8 changes: 6 additions & 2 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,14 @@ def _get_sysconfigdata_name():
f'_sysconfigdata_{sys.abiflags}_{sys.platform}_{multiarch}',
)

def _print_config_dict(d, stream):
print ("{", file=stream)
for k, v in sorted(d.items()):
print(f" {k!r}: {v!r},", file=stream)
print ("}", file=stream)

def _generate_posix_vars():
"""Generate the Python module containing build-time variables."""
import pprint
vars = {}
# load the installed Makefile:
makefile = get_makefile_filename()
Expand Down Expand Up @@ -523,7 +527,7 @@ def _generate_posix_vars():
f.write('# system configuration generated and used by'
' the sysconfig module\n')
f.write('build_time_vars = ')
pprint.pprint(vars, stream=f)
_print_config_dict(vars, stream=f)

# Create file used for sys.path fixup -- see Modules/getpath.c
with open('pybuilddir.txt', 'w', encoding='utf8') as f:
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def __exit__(self, *args):
manager = DefaultEnter()
self.assertIs(manager.__enter__(), manager)

def test_slots(self):
class DefaultContextManager(AbstractContextManager):
__slots__ = ()

def __exit__(self, *args):
super().__exit__(*args)

with self.assertRaises(AttributeError):
DefaultContextManager().var = 42

def test_exit_is_abstract(self):
class MissingExit(AbstractContextManager):
pass
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_contextlib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ async def __aexit__(self, *args):
async with manager as context:
self.assertIs(manager, context)

@_async_test
async def test_slots(self):
class DefaultAsyncContextManager(AbstractAsyncContextManager):
__slots__ = ()

async def __aexit__(self, *args):
await super().__aexit__(*args)

with self.assertRaises(AttributeError):
manager = DefaultAsyncContextManager()
manager.var = 42

@_async_test
async def test_async_gen_propagates_generator_exit(self):
# A regression test for https://bugs.python.org/issue33786.
Expand Down
Loading

0 comments on commit 48bea84

Please sign in to comment.