-
Notifications
You must be signed in to change notification settings - Fork 187
Allow docstrings given as raw unicode (ur""") #119
Conversation
0d967d4
to
9524fb4
Compare
9524fb4
to
6039dc6
Compare
This PR looks good, but I'd like to see some tests for this. |
I originally put in some tests, but |
@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 try:
eval('ur"foo"')
except SyntaxError:
print "Python 3"
else:
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. def raw_unicode():
pass
raw_unicode.__doc__ = eval(r'''ur"""Test unicode \xe9 and raw \\."""''') def raw_unicode():
eval(r'''ur"""Test unicode \xe9 and raw \\."""''') and you can't eval(r'''def raw_unicode(): ur"""Test unicode \xe9 and raw \\."""''') You can exec('def no_docstring(): pass') doesn't raise an error. |
Instead of adding a test in def test_unicode_raw():
if sys.version_info[0] >= 3:
return
with Pep257Env() as env:
with env.open('example.py', 'wt') as example:
example.write(textwrap.dedent("""\
def foo():
ur"""docstring"""
pass
"""))
# assert stuff |
4c8208d
to
98c230b
Compare
@Nurdok Thanks for the hint. I added a test. |
Allow docstrings given as raw unicode (ur""")
@jbeezley Merged! Thank you so much! |
Thank you @jbeezley ! |
Fixes #116.