Skip to content

Commit

Permalink
Merge branch 'main' into email-message-import
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Oct 3, 2023
2 parents c5e7a61 + 4227bfa commit bcaeb4c
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2437,9 +2437,9 @@ or if :attr:`~Connection.autocommit` is ``True``,
the context manager does nothing.

.. note::

The context manager neither implicitly opens a new transaction
nor closes the connection.
nor closes the connection. If you need a closing context manager, consider
using :meth:`contextlib.closing`.

.. testcode::

Expand Down
14 changes: 7 additions & 7 deletions Doc/requirements-oldest-sphinx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ python-docs-theme>=2022.1
# Sphinx 4.2 comes from ``needs_sphinx = '4.2'`` in ``Doc/conf.py``.

alabaster==0.7.13
Babel==2.12.1
Babel==2.13.0
certifi==2023.7.22
charset-normalizer==3.2.0
charset-normalizer==3.3.0
colorama==0.4.6
docutils==0.16
docutils==0.17.1
idna==3.4
imagesize==1.4.1
Jinja2==2.11.3
MarkupSafe==1.1.1
packaging==23.1
Jinja2==3.1.2
MarkupSafe==2.1.3
packaging==23.2
Pygments==2.16.1
requests==2.31.0
snowballstemmer==2.2.0
Expand All @@ -33,4 +33,4 @@ sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
urllib3==2.0.4
urllib3==2.0.6
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/pgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
'test_set',
'test_sqlite3',
'test_statistics',
'test_str',
'test_struct',
'test_tabnanny',
'test_time',
'test_unicode',
'test_xml_etree',
'test_xml_etree_c',
]
Expand Down
26 changes: 18 additions & 8 deletions Lib/test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,14 +936,24 @@ def __replace__(self, **changes):

def test_namedtuple(self):
from collections import namedtuple
Point = namedtuple('Point', 'x y', defaults=(0,))
p = Point(11, 22)
self.assertEqual(copy.replace(p), (11, 22))
self.assertEqual(copy.replace(p, x=1), (1, 22))
self.assertEqual(copy.replace(p, y=2), (11, 2))
self.assertEqual(copy.replace(p, x=1, y=2), (1, 2))
with self.assertRaisesRegex(ValueError, 'unexpected field name'):
copy.replace(p, x=1, error=2)
from typing import NamedTuple
PointFromCall = namedtuple('Point', 'x y', defaults=(0,))
class PointFromInheritance(PointFromCall):
pass
class PointFromClass(NamedTuple):
x: int
y: int = 0
for Point in (PointFromCall, PointFromInheritance, PointFromClass):
with self.subTest(Point=Point):
p = Point(11, 22)
self.assertIsInstance(p, Point)
self.assertEqual(copy.replace(p), (11, 22))
self.assertIsInstance(copy.replace(p), Point)
self.assertEqual(copy.replace(p, x=1), (1, 22))
self.assertEqual(copy.replace(p, y=2), (11, 2))
self.assertEqual(copy.replace(p, x=1, y=2), (1, 2))
with self.assertRaisesRegex(ValueError, 'unexpected field name'):
copy.replace(p, x=1, error=2)

def test_dataclass(self):
from dataclasses import dataclass
Expand Down
75 changes: 73 additions & 2 deletions Lib/test/test_structseq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import copy
import os
import pickle
import time
import unittest

Expand Down Expand Up @@ -106,9 +108,78 @@ def __len__(self):

self.assertRaises(Exc, time.struct_time, C())

def test_reduce(self):
def test_pickling(self):
t = time.gmtime()
x = t.__reduce__()
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
p = pickle.dumps(t, proto)
t2 = pickle.loads(p)
self.assertEqual(t2.__class__, t.__class__)
self.assertEqual(t2, t)
self.assertEqual(t2.tm_year, t.tm_year)
self.assertEqual(t2.tm_zone, t.tm_zone)

def test_pickling_with_unnamed_fields(self):
assert os.stat_result.n_unnamed_fields > 0

r = os.stat_result(range(os.stat_result.n_sequence_fields),
{'st_atime': 1.0, 'st_atime_ns': 2.0})
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
p = pickle.dumps(r, proto)
r2 = pickle.loads(p)
self.assertEqual(r2.__class__, r.__class__)
self.assertEqual(r2, r)
self.assertEqual(r2.st_mode, r.st_mode)
self.assertEqual(r2.st_atime, r.st_atime)
self.assertEqual(r2.st_atime_ns, r.st_atime_ns)

def test_copying(self):
n_fields = time.struct_time.n_fields
t = time.struct_time([[i] for i in range(n_fields)])

t2 = copy.copy(t)
self.assertEqual(t2.__class__, t.__class__)
self.assertEqual(t2, t)
self.assertEqual(t2.tm_year, t.tm_year)
self.assertEqual(t2.tm_zone, t.tm_zone)
self.assertIs(t2[0], t[0])
self.assertIs(t2.tm_year, t.tm_year)

t3 = copy.deepcopy(t)
self.assertEqual(t3.__class__, t.__class__)
self.assertEqual(t3, t)
self.assertEqual(t3.tm_year, t.tm_year)
self.assertEqual(t3.tm_zone, t.tm_zone)
self.assertIsNot(t3[0], t[0])
self.assertIsNot(t3.tm_year, t.tm_year)

def test_copying_with_unnamed_fields(self):
assert os.stat_result.n_unnamed_fields > 0

n_sequence_fields = os.stat_result.n_sequence_fields
r = os.stat_result([[i] for i in range(n_sequence_fields)],
{'st_atime': [1.0], 'st_atime_ns': [2.0]})

r2 = copy.copy(r)
self.assertEqual(r2.__class__, r.__class__)
self.assertEqual(r2, r)
self.assertEqual(r2.st_mode, r.st_mode)
self.assertEqual(r2.st_atime, r.st_atime)
self.assertEqual(r2.st_atime_ns, r.st_atime_ns)
self.assertIs(r2[0], r[0])
self.assertIs(r2.st_mode, r.st_mode)
self.assertIs(r2.st_atime, r.st_atime)
self.assertIs(r2.st_atime_ns, r.st_atime_ns)

r3 = copy.deepcopy(r)
self.assertEqual(r3.__class__, r.__class__)
self.assertEqual(r3, r)
self.assertEqual(r3.st_mode, r.st_mode)
self.assertEqual(r3.st_atime, r.st_atime)
self.assertEqual(r3.st_atime_ns, r.st_atime_ns)
self.assertIsNot(r3[0], r[0])
self.assertIsNot(r3.st_mode, r.st_mode)
self.assertIsNot(r3.st_atime, r.st_atime)
self.assertIsNot(r3.st_atime_ns, r.st_atime_ns)

def test_extended_getslice(self):
# Test extended slicing by comparing with list slicing.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add tests for pickling and copying PyStructSequence objects.
Patched by Xuehai Pan.

0 comments on commit bcaeb4c

Please sign in to comment.