readthedocs/commonmark.py

Problem with options={'smart':True} and python3

alvra opened this issue · 3 comments

alvra commented

When running on python3, integer division can give floats.
This gives a problem in https://github.com/rtfd/CommonMark-py/blob/master/CommonMark/inlines.py#L97 which now tries to multiply a string by a float.

  File "/usr/local/lib/python3.6/site-packages/CommonMark/inlines.py", line 98, in smart_dashes
    return ('\u2014' * em_count) + ('\u2013' * en_count)
TypeError: can't multiply sequence by non-int of type 'float'

The solution is to convert CommonMark.inlines.smart_dashes to use integer division (//) instead of true division (/). Adding from __future__ import division to the top of this file should also reveal this problem on python2. As far as I can tell, integer division is supported since python2.2.

sjml commented

Are there any near-future plans for a release? Would love to be using the library with Python 3 but this bug is currently holding me back, and the fix hasn't made its way to a release yet.

Ah sorry - I see there hasn't been a release that includes this fix last August. Thanks for reminding me, I will make a new commonmark-py release soon.

sjml commented

Thanks! Sorry to be "that guy;" I just stumbled over the bug. Thanks for all your great work!