Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6b0292

Browse files
committed
Apply suggestions from code review
1 parent 2a6259c commit a6b0292

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

Lib/collections/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def _make(cls, iterable):
457457
def _replace(self, /, **kwds):
458458
result = self._make(_map(kwds.pop, field_names, self))
459459
if kwds:
460-
raise ValueError(f'Got unexpected field name(s): {list(kwds)!r}')
460+
raise ValueError(f'Got unexpected field names: {list(kwds)!r}')
461461
return result
462462

463463
_replace.__doc__ = (f'Return a new {typename} object replacing specified '

Lib/test/test_structseq.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,14 @@ def test_match_args_with_unnamed_fields(self):
138138
def test_copy_replace_all_fields_visible(self):
139139
assert os.times_result.n_unnamed_fields == 0 and os.times_result.n_sequence_fields == os.times_result.n_fields
140140

141-
expected_args = ('user', 'system', 'children_user', 'children_system', 'elapsed')
142-
self.assertEqual(os.times_result.__match_args__, expected_args)
143-
self.assertEqual(os.times_result.n_fields, len(expected_args))
144-
145-
n_fields = os.times_result.n_fields # 5
146-
t = os.times_result(range(os.times_result.n_fields))
141+
t = os.times()
147142

148143
# visible fields
149-
self.assertEqual(copy.replace(t), tuple(range(n_fields)))
150-
self.assertEqual(copy.replace(t, user=1), (1, *range(1, n_fields)))
151-
self.assertEqual(copy.replace(t, system=2), (0, 2, *range(2, n_fields)))
152-
self.assertEqual(copy.replace(t, user=1, system=2), (1, 2, *range(2, n_fields)))
144+
self.assertEqual(copy.replace(t), t)
145+
self.assertIsInstance(copy.replace(t), os.times_result)
146+
self.assertEqual(copy.replace(t, user=1.5), (1.5, *t[1:]))
147+
self.assertEqual(copy.replace(t, system=2.5), (t[0], 2.5, *t[2:]))
148+
self.assertEqual(copy.replace(t, user=1.5, system=2.5), (1.5, 2.5, *t[2:]))
153149

154150
# unknown fields
155151
with self.assertRaisesRegex(TypeError, 'unexpected field name'):
@@ -162,25 +158,34 @@ def test_copy_replace_with_invisible_fields(self):
162158
assert t.n_unnamed_fields == 0 and t.n_sequence_fields < t.n_fields
163159

164160
# visible fields
165-
self.assertEqual(copy.replace(t), (1970, 1, 1, 0, 0, 0, 3, 1, 0))
166-
self.assertEqual(copy.replace(t, tm_year=2000),
167-
(2000, 1, 1, 0, 0, 0, 3, 1, 0))
168-
self.assertEqual(copy.replace(t, tm_mon=2),
169-
(1970, 2, 1, 0, 0, 0, 3, 1, 0))
170-
self.assertEqual(copy.replace(t, tm_year=2000, tm_mon=2),
171-
(2000, 2, 1, 0, 0, 0, 3, 1, 0))
161+
t2 = copy.replace(t)
162+
self.assertEqual(t2, (1970, 1, 1, 0, 0, 0, 3, 1, 0))
163+
self.assertIsInstance(t2, time.struct_time)
164+
t3 = copy.replace(t, tm_year=2000)
165+
self.assertEqual(t3, (2000, 1, 1, 0, 0, 0, 3, 1, 0))
166+
self.assertEqual(t3.tm_year, 2000)
167+
t4 = copy.replace(t, tm_mon=2)
168+
self.assertEqual(t4, (1970, 2, 1, 0, 0, 0, 3, 1, 0))
169+
self.assertEqual(t4.tm_mon, 2)
170+
t5 = copy.replace(t, tm_year=2000, tm_mon=2)
171+
self.assertEqual(t5, (2000, 2, 1, 0, 0, 0, 3, 1, 0))
172+
self.assertEqual(t5.tm_year, 2000)
173+
self.assertEqual(t5.tm_mon, 2)
172174

173175
# named invisible fields
174176
self.assertTrue(hasattr(t, 'tm_zone'), f"{t} has no attribute 'tm_zone'")
175177
with self.assertRaisesRegex(AttributeError, 'readonly attribute'):
176178
t.tm_zone = 'some other zone'
177-
t2 = copy.replace(t, tm_zone='some other zone')
178-
self.assertEqual(t, t2)
179-
self.assertEqual(t2.tm_zone, 'some other zone')
180-
t3 = copy.replace(t, tm_year=2000, tm_zone='some other zone')
181-
self.assertEqual(t3, (2000, 1, 1, 0, 0, 0, 3, 1, 0))
182-
self.assertEqual(t3.tm_year, 2000)
183-
self.assertEqual(t3.tm_zone, 'some other zone')
179+
self.assertEqual(t2.tm_zone, t.tm_zone)
180+
self.assertEqual(t3.tm_zone, t.tm_zone)
181+
self.assertEqual(t4.tm_zone, t.tm_zone)
182+
t6 = copy.replace(t, tm_zone='some other zone')
183+
self.assertEqual(t, t6)
184+
self.assertEqual(t6.tm_zone, 'some other zone')
185+
t7 = copy.replace(t, tm_year=2000, tm_zone='some other zone')
186+
self.assertEqual(t7, (2000, 1, 1, 0, 0, 0, 3, 1, 0))
187+
self.assertEqual(t7.tm_year, 2000)
188+
self.assertEqual(t7.tm_zone, 'some other zone')
184189

185190
# unknown fields
186191
with self.assertRaisesRegex(TypeError, 'unexpected field name'):

0 commit comments

Comments
 (0)