which is present in the example but missing from your function. It is a docstring. A common misconception is that docstrings are comments; this is not the case. Docstrings are part of your program and (usually) exist at runtime.
The docstring of an object is stored in the object’s __doc__ attribute. If the object has no docstring, this attribute is None.
The decorated_by function tries to add a string to a function’s existing docstring. If the input function does not have a docstring, as in your case, this fails because a str cannot be added to None.
def decorated_by(func):
if func.__doc__ is not None:
func.__doc__ += '\nDecorated by decorated_by.'
else:
func.__doc__ = 'Decorated by decorated_by.'
return func
The decorator in the book assumes that its argument will already have some docstring, and it appends a string to that value. It does not expect to create a docstring for a function that lacks one.