# It's a little hard to see my comments interspersed between # the gaudy output from doctest. Search for "(-)" and you'll # find them. 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] Python Type "help", "copyright", "credits" or "license" for more information. # (-) Our first attempt to run point.py failed due to blanks inside # the round brackets in the value returned from __rep__. [evaluate point.py] ********************************************************************** File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line ?, in __main__.Point.__repr__ Failed example: p2 == p1 Expected: True Got: False ********************************************************************** File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line ?, in __main__.Point.__repr__ Failed example: p1.__repr__() Expected: 'Point([6, 1, 2])' Got: 'Point( [6, 1, 2] )' ********************************************************************** 1 items had failures: 2 of 4 in __main__.Point.__repr__ ***Test Failed*** 2 failures. # (-) We took the blanks out, # but __repr__ still failed its doctests. # See the comments at the top of point.py for an explanation. [evaluate point.py] ********************************************************************** File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line ?, in __main__.Point.__repr__ Failed example: p2 == p1 Expected: True Got: False ********************************************************************** File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line ?, in __main__.Point.__repr__ Failed example: p1.__repr__() Expected: 'Point([6, 1, 2])' Got: 'Point([6, 1, 2])' ********************************************************************** 1 items had failures: 2 of 4 in __main__.Point.__repr__ # (1) The posted version of point.py fixes these problems, but # during lecture, we just commented out that method so we # could carry on without these errors. It evaluated successfully: [evaluate point.py] # (-) The client code worked fine, as long as we commented out the # code that changed coords in a foolish way. It would have even # worked if we'd changed coords in a sensible way, for instance # by saying somewhere.coords[0] = 22. [evaluate client.py] Pretty far! To be precise, distance 57.7408001330082 from the origin 55 4 # (-) But when we included that code, it caused an error to stop # the program. By putting a string in coordinates, we cause # distance_to_origin to fail when it attempts to compute the square # of that string! [evaluate client.py] Pretty far! To be precise, distance 57.7408001330082 from the origin 55 4 Traceback (most recent call last): File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line 22, in File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line 67, in distance_from_origin builtins.TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' # (-) We revised class Point to seize control over the client's # access to the coords instance variable. By using "property", we # made Points immutable. This stops clients not only from making # inappropriate changes to a Point, such as putting a string in it, # but from making any changes at all to a Point, even sensible ones. # Notice that, when the client tries to change a Point, the set_coordinate # method "raises an exception", and that causes the message # "Cannot reset coordinates" to be printed. # We will learn more about exceptions next week. [evaluate client.py] Pretty far! To be precise, distance 57.7408001330082 from the origin 55 4 Traceback (most recent call last): File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line 21, in File "/Applications/Wing101.app/Contents/Resources/src/debug/tserver/_sandbox.py", line 124, in set_coordinates builtins.Exception: Cannot reset coordinates. [evaluate client.py] Pretty far! To be precise, distance 57.7408001330082 from the origin 55 4 # (-) We then commented out the code that tried to change a Point. # The rest of our client code works fine, with no changes required at all, # even though all access to the instance variable coords is now handled # through the properly mechanism. [evaluate client.py] Pretty far! To be precise, distance 57.7408001330082 from the origin 55 4