When porting code to python 3, I came across a situation where the doxygen markup seems to tell python that we are trying to write a unicode literal, and importing the file fails with the error:
Traceback (most recent call last):
File "tests/testPsfIO.py", line 44, in <module>
import lsst.meas.algorithms as algorithms
File "/Users/nate/repos_lsst/meas_algorithms/python/lsst/meas/algorithms/__init__.py", line 29, in <module>
from .detection import *
File "/Users/nate/repos_lsst/meas_algorithms/python/lsst/meas/algorithms/detection.py", line 211
"""
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2129-2130: truncated \uXXXX escape
The docstring itself can be seen on: Github. Prefixing the docstring with r (telling python a raw string is desired) fixes the problem. I am wary of embedding the escape character in the docstring itself, as it may interfere with doxygen generation. Does anyone have thoughts or preferences?
For consistency, always use “”“triple double quotes”"" around docstrings. Use r""“raw triple double quotes”"" if you use any backslashes in your docstrings. For Unicode docstrings, use u""“Unicode triple-quoted strings”"" .
So it seems that using raw strings for the current generation of doxygen-marked-up docstrings is the way to go. Numpydoc won’t have this issue (maybe for latex math in docstrings, but I don’t recall ever doing anything special in those cases).
I tend to prefer “@” over “” in Doxygen universally (even in C++) for similar reasons - almost everything tries to interpret “”, but only Doxygen (of the things we run on our source files) pays attention to “@”.
Python 2, as is its wont, is far more relaxed about unicode in general so just silently ignores any unicode issues in strings. Python 3 cares deeply about unicode so complains.