Allow docstrings given as raw unicode (ur""")
This PR looks good, but I'd like to see some tests for this.
I originally put in some tests, but ur is a syntax error in python 3, so there needs to be some mechanism for adding a test file that is only executed on python 2. Do you have any suggestions for how to do this?
@jbeezley It's possible to check if the current Python is 2.x or 3.x. I think the "Pythonic" way is to check this specific syntax for SyntaxError, like so:
print "Python 3"
print "Python 2"
You're right, you can catch syntax errors in an eval, but I tried various iterations of it without success.
These raise missing docstring.
raw_unicode.__doc__ = eval(r'''ur"""Test unicode \xe9 and raw \\."""''')
eval(r'''ur"""Test unicode \xe9 and raw \\."""''')
and you can't eval a function definition like this.
eval(r'''def raw_unicode(): ur"""Test unicode \xe9 and raw \\."""''')
You can exec a definition, but that doesn't work with your tests. I.e.
exec('def no_docstring(): pass')
doesn't raise an error.
Instead of adding a test in test.py, I suggest you do it in test_pep257.py, where you can do something like this:
if sys.version_info >= 3:
with Pep257Env() as env:
with env.open('example.py', 'wt') as example:
# assert stuff
Adding a test for raw unicode docstrings
@Nurdok Thanks for the hint. I added a test.
@jbeezley Merged! Thank you so much!
Thank you @jbeezley !