Skip to content

Commit 45b3cd8

Browse files
Merge branch 'main' into clear_NameError_suggestion
2 parents 3006eef + dd8739a commit 45b3cd8

22 files changed

Lines changed: 158 additions & 62 deletions

Doc/library/tkinter.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ Base and mixin classes
20662066

20672067
.. method:: winfo_exists()
20682068

2069-
Return ``1`` if the widget exists, ``0`` otherwise.
2069+
Return ``True`` if the widget exists, ``False`` otherwise.
20702070

20712071
.. method:: winfo_fpixels(number)
20722072

@@ -2115,7 +2115,7 @@ Base and mixin classes
21152115

21162116
.. method:: winfo_ismapped()
21172117

2118-
Return ``1`` if the widget is currently mapped, ``0`` otherwise.
2118+
Return ``True`` if the widget is currently mapped, ``False`` otherwise.
21192119

21202120
.. method:: winfo_manager()
21212121

@@ -2246,8 +2246,8 @@ Base and mixin classes
22462246

22472247
.. method:: winfo_viewable()
22482248

2249-
Return ``1`` if the widget and all of its ancestors up through the
2250-
nearest toplevel window are mapped, ``0`` otherwise.
2249+
Return ``True`` if the widget and all of its ancestors up through the
2250+
nearest toplevel window are mapped, ``False`` otherwise.
22512251

22522252
.. method:: winfo_visual()
22532253

@@ -5737,7 +5737,7 @@ Widget classes
57375737
.. method:: edit_modified(arg=None)
57385738

57395739
If *arg* is omitted, return the current state of the modified flag as
5740-
``0`` or ``1``; the flag is set automatically whenever the text is
5740+
a :class:`bool`; the flag is set automatically whenever the text is
57415741
inserted or deleted.
57425742
Otherwise set the flag to the boolean *arg*.
57435743

Doc/library/tkinter.ttk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ ttk.Treeview
13721372
Without arguments, returns a tuple of all detached items,
13731373
but not their descendants (see :meth:`detached_all`).
13741374
With *item*, returns whether *item* is detached; since Tk 9.1, also
1375-
returns true if an ancestor of *item* is detached.
1375+
returns ``True`` if an ancestor of *item* is detached.
13761376

13771377
Requires Tk 9.0 or newer.
13781378

Lib/email/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,13 @@ def parsedate_to_datetime(data):
324324
if parsed_date_tz is None:
325325
raise ValueError('Invalid date value or format "%s"' % str(data))
326326
*dtuple, tz = parsed_date_tz
327-
if tz is None:
328-
return datetime.datetime(*dtuple[:6])
329-
return datetime.datetime(*dtuple[:6],
330-
tzinfo=datetime.timezone(datetime.timedelta(seconds=tz)))
327+
try:
328+
if tz is None:
329+
return datetime.datetime(*dtuple[:6])
330+
return datetime.datetime(*dtuple[:6],
331+
tzinfo=datetime.timezone(datetime.timedelta(seconds=tz)))
332+
except OverflowError as exc:
333+
raise ValueError('Invalid date value or format "%s"' % str(data)) from exc
331334

332335

333336
def parseaddr(addr, *, strict=True):

Lib/imaplib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def select(self, mailbox='INBOX', readonly=False):
960960
if __debug__:
961961
if self.debug >= 1:
962962
self._dump_ur(self.untagged_responses)
963-
raise self.readonly('%s is not writable' % mailbox)
963+
raise self.readonly('%r is not writable' % (mailbox,))
964964
return typ, self.untagged_responses.get('EXISTS', [None])
965965

966966

@@ -1085,7 +1085,7 @@ def uid(self, command, *args):
10851085
"""
10861086
command = command.upper()
10871087
if not command in Commands:
1088-
raise self.error("Unknown IMAP4 UID command: %s" % command)
1088+
raise self.error("Unknown IMAP4 UID command: %r" % (command,))
10891089
if self.state not in Commands[command]:
10901090
raise self.error("command %s illegal in state %s, "
10911091
"only allowed in states %s" %

Lib/test/test_email/test_headerregistry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ def test_invalid_date_value(self):
221221
self.assertEqual(len(h.defects), 1)
222222
self.assertIsInstance(h.defects[0], errors.InvalidDateDefect)
223223

224+
def test_out_of_range_date_value(self):
225+
s = 'Mon, 20 Nov 9999999999 12:00:00 +0000'
226+
h = self.make_header('date', s)
227+
self.assertEqual(h, s)
228+
self.assertIsNone(h.datetime)
229+
self.assertEqual(len(h.defects), 1)
230+
self.assertIsInstance(h.defects[0], errors.InvalidDateDefect)
231+
224232
def test_datetime_read_only(self):
225233
h = self.make_header('date', self.datestring)
226234
with self.assertRaises(AttributeError):

Lib/test/test_email/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def test_parsedate_to_datetime_with_invalid_raises_valueerror(self):
7777
with self.subTest(dtstr=dtstr):
7878
self.assertRaises(ValueError, utils.parsedate_to_datetime, dtstr)
7979

80+
def test_parsedate_to_datetime_out_of_range_raises_valueerror(self):
81+
out_of_range_dates = [
82+
'Mon, 20 Nov 9999999999 12:00:00 +0000',
83+
'Mon, 20 Nov 2017 12:00:00 +24000000000000',
84+
]
85+
for dtstr in out_of_range_dates:
86+
with self.subTest(dtstr=dtstr):
87+
self.assertRaises(ValueError, utils.parsedate_to_datetime, dtstr)
88+
8089
class LocaltimeTests(unittest.TestCase):
8190

8291
def test_localtime_is_tz_aware_daylight_true(self):

Lib/test/test_imaplib.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,32 @@ def cmd_CAPABILITY(self, tag, args):
995995
client.login('user', 'pass')
996996
self.assertIn('ENABLE', client.capabilities)
997997

998+
def test_readonly_error_reports_mailbox(self):
999+
# The read-only error reports the mailbox via repr(), which also
1000+
# avoids BytesWarning for a bytes mailbox under -bb.
1001+
class ReadOnlyHandler(SimpleIMAPHandler):
1002+
def cmd_SELECT(self, tag, args):
1003+
self._send_line(b'* 2 EXISTS')
1004+
self._send_tagged(tag, 'OK', '[READ-ONLY] SELECT completed.')
1005+
client, _ = self._setup(ReadOnlyHandler)
1006+
client.login('user', 'pass')
1007+
for mailbox, expected in [('INBOX', "'INBOX'"), (b'INBOX', r"b'INBOX'")]:
1008+
with self.subTest(mailbox=mailbox):
1009+
with self.assertRaisesRegex(imaplib.IMAP4.readonly,
1010+
r"%s is not writable" % expected):
1011+
client.select(mailbox)
1012+
1013+
def test_uid_unknown_command_reports_command(self):
1014+
# The unknown-UID-command error reports the command via repr(), which
1015+
# also avoids BytesWarning for a bytes command under -bb.
1016+
client, _ = self._setup(SimpleIMAPHandler)
1017+
for command, expected in [('BOGUS', "'BOGUS'"), (b'BOGUS', r"b'BOGUS'")]:
1018+
with self.subTest(command=command):
1019+
with self.assertRaisesRegex(
1020+
imaplib.IMAP4.error,
1021+
r"Unknown IMAP4 UID command: %s" % expected):
1022+
client.uid(command, '1')
1023+
9981024
def test_logout(self):
9991025
client, _ = self._setup(SimpleIMAPHandler)
10001026
typ, data = client.login('user', 'pass')

Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,9 @@ class TestBinaryFormatValidation(BinaryFormatTestBase):
999999
"""Tests for malformed binary files."""
10001000

10011001
HDR_OFF_SAMPLES = 28
1002-
HDR_OFF_THREADS = 32
1003-
HDR_OFF_STR_TABLE = 36
1004-
HDR_OFF_FRAME_TABLE = 44
1002+
HDR_OFF_THREADS = 36
1003+
HDR_OFF_STR_TABLE = 40
1004+
HDR_OFF_FRAME_TABLE = 48
10051005
FILE_HEADER_PLACEHOLDER_SIZE = 64
10061006
FILE_FOOTER_SIZE = 32
10071007
FTR_OFF_STRINGS = 0
@@ -1039,7 +1039,7 @@ def test_replay_rejects_sample_count_mismatch(self):
10391039

10401040
with open(filename, "r+b") as raw:
10411041
raw.seek(self.HDR_OFF_SAMPLES)
1042-
raw.write(struct.pack("=I", 2))
1042+
raw.write(struct.pack("=Q", 2))
10431043

10441044
with BinaryReader(filename) as reader:
10451045
self.assertEqual(reader.get_info()["sample_count"], 2)
@@ -1149,6 +1149,31 @@ def test_open_accepts_frame_count_at_capacity_boundary(self):
11491149
f"possible {max_frames}",
11501150
)
11511151

1152+
def test_sample_count_reads_full_64_bits(self):
1153+
"""sample_count values requiring the upper 32 bits decode correctly."""
1154+
filename = self.create_binary_file([], compression="none")
1155+
big_count = 0x1_0002_0003
1156+
1157+
with open(filename, "r+b") as raw:
1158+
raw.seek(self.HDR_OFF_SAMPLES)
1159+
raw.write(struct.pack("=Q", big_count))
1160+
1161+
with BinaryReader(filename) as reader:
1162+
self.assertEqual(reader.get_info()["sample_count"], big_count)
1163+
1164+
def test_sample_count_boundary_values(self):
1165+
"""Values above the old u32 ceiling decode fine."""
1166+
filename = self.create_binary_file([], compression="none")
1167+
1168+
for value in (0xFFFFFFFF - 1, 0xFFFFFFFF, 0xFFFFFFFF + 1):
1169+
with self.subTest(value=value):
1170+
with open(filename, "r+b") as raw:
1171+
raw.seek(self.HDR_OFF_SAMPLES)
1172+
raw.write(struct.pack("=Q", value))
1173+
1174+
with BinaryReader(filename) as reader:
1175+
self.assertEqual(reader.get_info()["sample_count"], value)
1176+
11521177

11531178
class TestBinaryEncodings(BinaryFormatTestBase):
11541179
"""Tests specifically targeting different stack encodings."""

Lib/test/test_tkinter/test_images.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,12 @@ def test_data(self):
694694

695695
def test_transparency(self):
696696
image = self.create()
697-
self.assertEqual(image.transparency_get(0, 0), True)
698-
self.assertEqual(image.transparency_get(4, 6), False)
697+
self.assertIs(image.transparency_get(0, 0), True)
698+
self.assertIs(image.transparency_get(4, 6), False)
699699
image.transparency_set(4, 6, True)
700-
self.assertEqual(image.transparency_get(4, 6), True)
700+
self.assertIs(image.transparency_get(4, 6), True)
701701
image.transparency_set(4, 6, False)
702-
self.assertEqual(image.transparency_get(4, 6), False)
702+
self.assertIs(image.transparency_get(4, 6), False)
703703
self.assertRaises(tkinter.TclError, image.transparency_get, -1, 0)
704704
self.assertRaises(tkinter.TclError, image.transparency_get, 16, 0)
705705
self.assertRaises(tkinter.TclError, image.transparency_set, -1, 0, True)

Lib/test/test_tkinter/test_misc.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,26 @@ def test_winfo_visual_info(self):
905905
self.assertIsInstance(name, str)
906906
self.assertIsInstance(depth, int)
907907

908+
def test_winfo_exists(self):
909+
f = tkinter.Frame(self.root)
910+
self.assertIs(f.winfo_exists(), True)
911+
f.destroy()
912+
self.assertIs(f.winfo_exists(), False)
913+
914+
def test_winfo_ismapped(self):
915+
f = tkinter.Frame(self.root)
916+
self.assertIs(f.winfo_ismapped(), False)
917+
f.pack()
918+
self.root.update()
919+
self.assertIs(f.winfo_ismapped(), True)
920+
908921
def test_winfo_viewable(self):
909922
f = tkinter.Frame(self.root)
910-
self.assertFalse(f.winfo_viewable())
923+
self.assertIs(f.winfo_viewable(), False)
911924
f.pack()
912925
f.wait_visibility()
913926
self.root.update()
914-
self.assertTrue(f.winfo_viewable())
927+
self.assertIs(f.winfo_viewable(), True)
915928

916929
@requires_tk(9, 1)
917930
def test_winfo_isdark(self):

0 commit comments

Comments
 (0)