I compiled this code, and seems that if you don't explicitly specify 

.. code-block:: python

sometimes the syntax hightlighting doesn't work. So please add this for all the code blocks.