Skip to content

Commit 1ce625e

Browse files
committed
Updating example code to address various errors
1 parent 7e75b47 commit 1ce625e

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

example_code/item_04.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def close_open_files():
234234
'Today\'s soup is %(soup)s, '
235235
'buy one get two %(oyster)s oysters, '
236236
'and our special entrée is %(special)s.')
237-
old_formatted = template % {
237+
old_formatted = old_template % {
238238
'soup': 'lentil',
239239
'oyster': 'kumamoto',
240240
'special': 'schnitzel',

example_code/item_34.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def my_generator():
7777
received = yield 1
7878
print(f'received = {received}')
7979

80-
it = iter(my_generator())
80+
it = my_generator()
8181
output = next(it) # Get first generator output
8282
print(f'output = {output}')
8383

@@ -90,7 +90,7 @@ def my_generator():
9090

9191

9292
# Example 4
93-
it = iter(my_generator())
93+
it = my_generator()
9494
output = it.send(None) # Get first generator output
9595
print(f'output = {output}')
9696

example_code/item_48.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __new__(meta, name, bases, class_dict):
5454
print(f'* Running {meta}.__new__ for {name}')
5555
print('Bases:', bases)
5656
print = pprint
57-
print(class_dict)
57+
print(class_dict)
5858
print = orig_print
5959
return type.__new__(meta, name, bases, class_dict)
6060

@@ -124,7 +124,7 @@ class BetterPolygon:
124124
def __init_subclass__(cls):
125125
super().__init_subclass__()
126126
if cls.sides < 3:
127-
raise ValueError('Polygons need 3+ sides')
127+
raise ValueError('Polygons need 3+ sides')
128128

129129
@classmethod
130130
def interior_angles(cls):
@@ -238,24 +238,24 @@ class Filled:
238238
def __init_subclass__(cls):
239239
super().__init_subclass__()
240240
if cls.color not in ('red', 'green', 'blue'):
241-
raise ValueError('Fills need a valid color')
241+
raise ValueError('Fills need a valid color')
242242

243243

244244
# Example 13
245-
class RedTriangle(Filled, Polygon):
245+
class RedTriangle(Filled, BetterPolygon):
246246
color = 'red'
247247
sides = 3
248248

249249
ruddy = RedTriangle()
250250
assert isinstance(ruddy, Filled)
251-
assert isinstance(ruddy, Polygon)
251+
assert isinstance(ruddy, BetterPolygon)
252252

253253

254254
# Example 14
255255
try:
256256
print('Before class')
257257

258-
class BlueLine(Filled, Polygon):
258+
class BlueLine(Filled, BetterPolygon):
259259
color = 'blue'
260260
sides = 2
261261

@@ -270,7 +270,7 @@ class BlueLine(Filled, Polygon):
270270
try:
271271
print('Before class')
272272

273-
class BeigeSquare(Filled, Polygon):
273+
class BeigeSquare(Filled, BetterPolygon):
274274
color = 'beige'
275275
sides = 4
276276

example_code/item_58.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ def game_logic(state, neighbors):
194194

195195

196196
# Example 5
197+
# Clear the sentinel object from the out queue
198+
for _ in out_queue:
199+
pass
200+
197201
# Restore the working version of this function
198202
def game_logic(state, neighbors):
199203
if state == ALIVE:

example_code/item_78.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def do_rounds(database, species, *, utcnow=datetime.utcnow):
269269

270270
for name, last_mealtime in animals:
271271
if (now - last_mealtime) > feeding_timedelta:
272-
feed_func(database, name, now)
272+
feed_animal(database, name, now)
273273
fed += 1
274274

275275
return fed
@@ -297,9 +297,9 @@ def do_rounds(database, species, *, utcnow=datetime.utcnow):
297297
result = do_rounds(database, 'Meerkat', utcnow=now_func)
298298
assert result == 2
299299

300-
food_func.assert_called_once_with(database, 'Meerkat')
301-
animals_func.assert_called_once_with(database, 'Meerkat')
302-
feed_func.assert_has_calls(
300+
get_food_period.assert_called_once_with(database, 'Meerkat')
301+
get_animals.assert_called_once_with(database, 'Meerkat')
302+
feed_animal.assert_has_calls(
303303
[
304304
call(database, 'Spot', now_func.return_value),
305305
call(database, 'Fluffy', now_func.return_value),

0 commit comments

Comments
 (0)