Skip to content

Commit d13d63d

Browse files
Minor adjustments
1 parent 95b0c7a commit d13d63d

3 files changed

Lines changed: 6 additions & 20 deletions

File tree

‎Lib/test/test_augassign.py‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Augmented assignment test.
22

3-
import enum
4-
import operator
53
import unittest
64

75

@@ -67,34 +65,23 @@ def testSequences(self):
6765
self.assertTrue(x is y)
6866

6967
def testSequenceRepeatRightOperand(self):
70-
# gh-XXXXXX: "n *= seq" must fall back to seq's repeat, as "n * seq"
71-
# does, when n's type has sequence methods but no repeat slot.
68+
# gh-161968
7269
class MyInt(int):
7370
pass
7471
class Index:
7572
def __index__(self):
7673
return 2
77-
class Number(enum.IntEnum):
78-
TWO = 2
79-
for n in MyInt(2), Index(), Number.TWO:
80-
for seq in [1], (1,), 'a', b'a', bytearray(b'a'):
81-
with self.subTest(n=n, seq=seq):
82-
expected = n * seq
83-
x = n
84-
x *= seq
85-
self.assertEqual(x, expected)
86-
self.assertEqual(operator.imul(n, seq), expected)
8774

88-
# The right operand is not modified in place.
8975
seq = [1]
9076
x = MyInt(2)
9177
x *= seq
9278
self.assertEqual(x, [1, 1])
79+
# The right operand is not modified in place.
9380
self.assertEqual(seq, [1])
9481

9582
x = Index()
96-
with self.assertRaises(TypeError):
97-
x *= Index()
83+
x *= 'a'
84+
self.assertEqual(x, 'aa')
9885

9986
def testCustomMethods1(self):
10087

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``x *= seq`` raising :exc:`TypeError` when ``x`` is an instance of an
2+
:class:`int` subclass or of a class defining :meth:`~object.__index__`.

‎Misc/NEWS.d/next/Core_and_Builtins/2026-11-13-00-00-00.gh-issue-161968.ytuft5z.rst‎

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

0 commit comments

Comments
 (0)