Errata

Robust Python

Errata for Robust Python

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Page p. 130
the element of caution

If you override comparison functions, do not specify `order=True`, as that will raise a `ValueError`.

should be

If you override comparison functions, do not specify `order=True`, as that will raise a `TypeError`.

Note from the Author or Editor:
Good catch on this! The exception type should be changed to `TypeError`, jsut as Yuri suggested.

Yuri  Dec 11, 2022  Dec 16, 2022
Page p. 80
Top third

"you" is duplicated in "you you can control configuration ..." when dicussing `mypy`.

Note from the Author or Editor:
Confirmed, the extra you needs to be removed. Thanks for the catch.

Vadim  Jan 01, 2023 
Page p. 81 (section 'Configuring Mypy')
First full paragraph

"typechecker" misspelled as "typechcecker"

Note from the Author or Editor:
Thanks for the find. Typechcecker should be indeed be typechecker

Vadim  Jan 01, 2023 
Page p. 130
"Equality" section

Text is: "If you want to be able to test equality ... between two data classes". I believe this should instead be "If you want to test equality ... between two _instances_ of a data class".

Note from the Author or Editor:
Thanks for the catch! Prod Team - please make the changes that Vadim suggested. "between two data classes" should be changed to "between two instances of a data class"

Vadim  Jan 08, 2023 
Page p. 263
code list above the scorpion icon

``packge_order(order)``

should be

``package_order(order)``

Note from the Author or Editor:
Thanks for submitting the errata. I can confirm the typo and packge_order should be package_order

Yuri  Feb 21, 2023 
Page 8
Line 1

Line 1 (error): --------------------- v
ingredient.adjust_propoprtion(...
ingredient.adjust_proportion(...
Line 1 (corr.): --------------------- ^

Note from the Author or Editor:
Thank you for pointing this out. The top line on page 8 should absolutely be adjust_proportion instead of adjust_propoprtion.

Anonymous  Sep 14, 2021  Dec 16, 2022
Page 13. Protocols
Tension Between Typing Systems, after 2nd code example

The code example shows a function signature:
```
def split_dish(dish: ???) -> ????:
```
and then asks the reader:
"What should the parameter `order` be typed as?"

I think `order` should actually be the parameter `dish` in the `split_dish` function.

Note from the Author or Editor:
Thanks for picking this out, it should absolutely be `dish` instead of `order`.

As Ben noted, the first sentence of that paragraph should be changed from "What should the parameter `order` be typed as?" to "What should the parameter `dish`be typed as?"

Ben Shulman  Jul 14, 2022  Dec 16, 2022
Page 15
first sample code

The code "def create_author_count_mapping(cookbooks: List[Cookbook]):"
should be


"def create_author_count_mapping(cookbooks: list[Cookbook]):"




Note from the Author or Editor:
Thank you for pointing this out.

There are two code examples on page 15 that need changing - the one under the defaultdict section and the one under Counter. In both cases, the List[Cookbook]` should be changed to list[Cookbook].

The lowercase "list" is consistent with the rest of the book.

Sungjoon Kim  Sep 13, 2021  Dec 16, 2022
Page 26
line 15

“A datetime supports addition and subtraction, but not of other datetimes.”

This is statement is true with regard to the addition of datetimes, but false with regard to the subtraction of datetimes.

While datetime.datetime.__add__ supports addition only of a datetime.timedelta value, datetime.datetime.__sub__ supports subtraction of either a datetime.timedelta value or a datetime.datetime value. Subtracting a timedelta value from a datetime produces a datetime result; subtracting a datetime value from another datetime value produces a timedelta value:

>>> import datetime
>>> d1 = datetime.datetime(2022,1,31)
>>> d2 = datetime.datetime(2022,1,1)
>>> d1-d2
datetime.timedelta(days=30)
>>>

Note from the Author or Editor:
Thank you for pointing out this very incorrect generalization. The first two sentences of this paragraph should be changed from :

"A datetime supports addition and subtraction, but not of other datetimes. We only add time deltas (such as adding a day or subtracting a year)."

to

"A datetime supports addition, but not of other datetimes. We only add time deltas (such as adding a day or adding a week)."




Additionally, the bullet list right above this paragraph on page 26 has the second bullet as "Mathematical operations such as addition and subtraction of time deltas."

It should now read instead:

"Mathematical operations such as addition of time deltas and subtraction of both time deltas and other datetime objects."

The words "of time deltas" and "of both time deltas and other datetime objects" should be italicized, and datetime should be in the code font.

Anonymous  Jan 31, 2022  Dec 16, 2022
Page 53
Line 1

You import Union then use optional. should be import optional then use optional.

Note from the Author or Editor:
This is a technical mistake using the wrong import. The first line of the code block at the top of page 53 should change from "from typing import Union" to "from typing import Optional".

Thank you for pointing this out.

Ben  Sep 08, 2021  Dec 16, 2022
Printed,
Page 118
Paragraph starting with "This is great"

The numbers used in the end of this paragraph are wrong, which makes the point that is being made incorrect. Furthermore, some readers have highlighted this as a bit confusing, so I've also added a clarification. (Note I'm using tick marks (`) to indicate code font, they are not meant to be literal in the text.

What needs to be changed:
you cannot use the values 1 through 4 (inclusive) for your `Enum` because 4 will "bitwise and" for the values 1,2, and 4 which is probably not what you want.

Should be changed to:
you cannot use the values 1 through 3 (inclusive) for your `Flag`, because if you set the `Flag` to be value 3, performing a "bitwise and" (&) of 1,2, or 3 will all evaluate to `True` when converted to a boolean value, which makes it difficult to use the `Flag` effectively.

Pat Viafore
 
Oct 16, 2021  Dec 16, 2022
Page 118
Second definition of Allergen(Flag)

Definitions of SEAFOOD and ALL_NUTS are indented and are defined inside Allergen EnumType. This code will not work, raising a KeyError and a TypeError.

Note from the Author or Editor:
This is correct, the SEAFOOD and ALL_NUTS lines need to be dedented (the rest of the lines above it should stay indented)

....
....
DAIRY=auto()
SEAFOOD = Allergen.FISH | Allergen.SHELLFISH
ALL_NUTS = Allergen.TREE_NUTS | Allergen.PEANUTS

Vadim  Mar 03, 2023 
Page 123
line 4

“However you still need to be able compose multiple fields…”:

The word “to” is missing between “able” and “compose”.

Note from the Author or Editor:
change "able compose" to "able to compose"

Anonymous  Jan 31, 2022  Dec 16, 2022
Page 129
line 16

The definition of nutritionals on line 16 uses the NutritionInformation data class that has not yet been defined. It is defined further down the page after the order=True argument to the @dataclass decorator, but using it before it is introduced is confusing (albeit only briefly). But when I initially read the assignment to nutritionals I did wonder what underlying type NutritionInformation was.

Note from the Author or Editor:
Thanks for pointing out the confusing order.

The first paragraph in the "Relational Comparison" section ends with a "number of calories of carbohydrates". There should be a new sentence after this closing sentence, so that it reads as follows

... such as the number of calories, or carbohydrates. Suppose I have a list of dataclass objects called `NutritionInformation`, each of which containing number of calories, grams of fat, and grams of carbohydrates. I have a list of `nutritionals` that I want to ultimately sort:



Note that I am using backticks (`) to represent code font, and should not be put verbatim into the text.

Anonymous  Jan 31, 2022  Dec 16, 2022
Printed, PDF
Page 136
Bottom of page

I am using a technically incorrect term throughout the book by using the term "constructor" when talking about an __init__ method. Special thanks to Henrik Strøm for pointing this out (twitter.com/henrikstroem/status/1528345763230654465)

Note, all of this text uses backticks (`abcdef`) to indicate code font.
There are many fixes that need to be put in to correct this usage of incorrect term.

On page 86, the callout numbered #2 should be changed from "A description of the constructor" to "A description of the `__init___` method."

On page 136, in the paragraph that starts "That's really frustrating", the sentence that goes "You need to explicitly define how a class gets constructed, which is done through a special method called a constructor." needs to be changed to "You need to explicitly define how a class gets initialized, which is done through a special method called `__init__`. Please note that "constructors" in the index corresponds to this page; that should be changed to "__init__ method" in the index.

On page 136, the heading "Constructors" should be up dated to "Class initialization". The first paragraph of this section should be changed from "A constructor describes how to initialize your class. You define a constructor with an `__init_`_ method" to "When you construct a new instance of a class, you control how that class is initialized with an `__init__` method. Please note that "constructors" in the index corresponds to this page; that should be changed to "__init__ method" in the index.

On page 137, the paragraph that starts with "Notice that I tweaked" has two uses of the word constructor: "...variables in a constructor." and "The constructor is a special method..." These should be changed to "...variables in `__init__` and "This special method...", respectively.

On page 138, there is a sentence at the top of the page: "Let's start with the constructor" should be changed to "Let's start with the `__init__` method."

On page 138, the first bullet that starts with "`dough_radius_in_inches` is an integer has the phrase: "into the constructor". This should be "into the `__init__` method" . The next bullet has a phrase "preventing construction of the class" to "preventing initialization of the class"

On page 143, The first paragraph under "Consuming Your Class" has two mentions to constructors: "... in the constructor is a great way..." and "A constructor is typically...". These should be changed to "...in the `__init__` method is a great way..." and "The `__init__` method is typically...", respectively. Please note that "constructors" in the index corresponds to this page; that should be changed to "__init__ method" in the index.

On page 147, The paragraph that starts with "So far, I've covered two parts of the API, needs two changes: Remove the parenthetical "(constructor)" and change "I don't have much more to say about the constructor;" to "I don't have much more to say about the `__init__` method;"

On page 166, the bullet point "In Chapter 10" should" say "to initialize a class" instead of "to construct a class". The term "constructed" should be changed "instantiated"

On page 174, the chapter that starts with "Suppose I want my food truck" calls out" `FoodTruck`'s constructor", which should be changed to `FoodTruck`'s `__init__` method

On page 175, in the paragraph starting with "I am using a special function", has a phrase "`Restaurant`'s constructor" which should be changed to "`Restaurants`'s `__init__` method.

On page 183, bottom paragraph, "Each of the member fields set in the constructor" should be changed to "Each of the member fields set in `__init__`"

On page 196, the note mentions "concerning setting variables in constructors" which should be set to "concerning setting variables in `__init__` methods".

On page 203, the bottom paragraph has a phrase " could you imagine opening up a constructor" to "could you imagine opening up an `__init__` method"

On page 210, the sentence "However, pydantic protects the invariant, even when you call a constructor or set a field" should be changed to "However, pydantic protects the invariant, even when you initialize a type or set a field"

On page 290, the last paragraph starts with "In this case, I've defined a constructor". This should be changed to "In this case, I've defined an `__init__` method."

On page 334, the last paragraph has a phrase "In the constructor, I set up `self.recommender`" which should be changed to "In the `__init__` method, I set up `self.recommender`"

Pat Viafore
 
May 22, 2022  Dec 16, 2022
Page 145
Line 15

Line 15 (error): ----------- v
@contextlib.contetxtmanager
@contextlib.contextmanager
Line 15 (corr.): ----------- ^

Note from the Author or Editor:
Confirmed, thank you for pointing it out.

The text should be changed from @contextlib.contetxtmanager to @contextlib.contextmanager.

Anonymous  Oct 01, 2021  Dec 16, 2022
Page 151
Paragraph 3, Sentence 3

The author discusses that a function that has nothing to do with invariants or a particular class's members should be a free function (aka it should live at module scope). The language is specifically as follows:

"This *class* is better served by living at module scope and outside of your class."

Should this read instead, as follows?

"This *function* is better served by living at module scope and outside of your class."

We are speaking about the function in question, after all. I believe that the author simply meant "this function", instead of "this class".

Note from the Author or Editor:
Thank you for pointing this out. It should indeed be "function". "This class is better served" ... should be changed to "This function is better served"

Anonymous  Oct 03, 2021  Dec 16, 2022
Page 162
Code: Line 25

def order_items(store: Store, item: items: Iterable[Item]) -> bool:

should be

def order_items(store: Store, items: Iterable[Item]) -> bool:

Note from the Author or Editor:
Thank you for catching this. The word "item:" should be removed from this line, just as you suggested.

Yuri  Dec 11, 2022  Dec 16, 2022
Page 193
the end of line

def split_dish(order: Splittable) -> tuple[Splittable, Splittable]:

should be

def split_dish(dish: Splittable) -> tuple[Splittable, Splittable]:

Note from the Author or Editor:
Thanks for the catch. This should be changed from "order" to "dish" as Yuri suggested

Yuri  Feb 27, 2023 
Page 193
2nd code block in section "Defining a Protocol"

def split_in_half(self) -> ('BLTSandwich', 'BLTSandwich'):

is wrong and invalid Python syntax and should be

def split_in_half(self) -> tuple['BLTSandwich', 'BLTSandwich']:

Note from the Author or Editor:
Thanks for the catch. This should be changed as described

def split_in_half(self) -> ('BLTSandwich', 'BLTSandwich'):

should be changed to

def split_in_half(self) -> tuple['BLTSandwich', 'BLTSandwich']:

Philipp Hahn   Apr 07, 2023 
Page 220
Code block

In method "send_text" the last "raise NotImplementedError(...)" should probably be put unter an "else:" statement: Otherwise each of the "pass" blocks require a "return" statement to exit early from the method to NOT execute the "raise" statement at the end of the method.

Note from the Author or Editor:
Thank you for pointing that out.

The line in question should be changed from

raise NotImplementedError("Unsupported Notification Method")


to


else:
raise NotImplementedError("Unsupported Notification Method")


(the (raise NotImplementedError...) is indented underneath the else block

Philipp Hahn   Apr 07, 2023 
Printed
Page 231
Figure 16-4

In the figure 16-4, titled More sensible dependencies, the arrow for "Get Menu Items" is pointed in the wrong direction. The arrow should be pointing from Payment System to Pizza Making System.

Pat Viafore
 
Feb 07, 2023 
Page 235
2nd code example

On the third line of the second code example on the page, the `pizza_maker` name has been wrongly written as `pizza.maker`. That is,

pizza.maker.wait_for_reconfiguration()

should be

pizza_maker.wait_for_reconfiguration()

Note from the Author or Editor:
Thanks for the catch!

The reporter's fix is what's needed: change pizza.maker to pizza_maker on page 235

Stig Johan  Jun 16, 2022  Dec 16, 2022
Page 252
Code

def repeat(func: Callable, times: int = 1) -> Callable:
''' this is a function that calls the wrapped function
a specified number of times
'''
def _wrapper(*args, **kwargs):
for _ in range(times):
func(*args, **kwargs)
return _wrapper

should be

def repeat(times: int = 1) -> Callable:
"""this is a function that calls the wrapped function a specified number of times"""
def _repeat(func: Callable):
@functools.wraps(func)
def _wrapper(*args, **kwargs):
for _ in range(times):
func(*args, **kwargs)
return _wrapper
return _repeat

Note from the Author or Editor:
Thank you for the catch of the missing wrapper function. The change that you have suggested is accurate and is what should show up in the book.

Production team, if the whitespace was not preserved in Yuri's message, please reach out to me and I can make the change, as the levels of indentation are important for this code.

Yuri  Dec 11, 2022  Dec 16, 2022
Printed
Page 305
First code block

The line of code says "st \etup_bacon_cheeseburger" That should just be changed to setup_bacon_cheeseburger

Pat Viafore
 
Aug 10, 2022  Dec 16, 2022
Page 306
1st code block last line

The 2nd s et of parentheses should be removed from
test_database.cleanup()()

Note from the Author or Editor:
Thank you for another catch. Prod team, please apply the suggested change by removing the second set of parentheses

Philipp Hahn   Apr 09, 2023 
Page 318
2nd Ghekin code

Line 2-4 should be indented right to make only the 1st line stay left:
Scenario: ...
Given ...
When ...
Then ...

Note from the Author or Editor:
Thank you for the catch.

Prod team: The lines starting with "Given", "When", and "Then" (3 lines) should all be indented, similar to the code example preceding it on the page.

Philipp Hahn   Apr 09, 2023 
Page 3337
Chapter 8, Enumerations, 3rd paragraph

In the eBook:
One of the most popluar offerings...
---------------------------^

should read:
One of the most popular offerings...
---------------------------^

Note from the Author or Editor:
Confirmed, thank you for pointing it out

On page 112 of the print book, the first sentence of the third paragraph under the Enumerations section should be changed from "One of the most popluar offerings" to "One of the most popular offerings"

Madou  Oct 12, 2021  Dec 16, 2022