-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python dual support #266
Python dual support #266
Conversation
Note: I dislike unicode_literals because it causes great confusion when debugging. You can no longer tell what a bare literal is just by looking at the literal. You have to look at the top of the file for a from future import as well as at the literal. (Things get even worse when some code combines a literal from a file with unicode_literals with a literal from a file without unicode_literals). It is a little verbosity in font.py but I'd use something like this to do it instead: from urwid.compat import text_type
def to_text(obj, encoding='utf-8', errors='strict'):
if isinstance(obj, text_type):
return obj
elif isinstance(obj, bytes):
return obj.decode(encoding, errors)
[...]
""", to_text(r"""
"###$$$%%%'*++,--.///:;==???[[\\\]]^__`
" ┼┼┌┼┐O /' /.. _┌─┐┌ \ ┐^ `
┼┼└┼┐ / * ┼ ─ / ., _ ┌┘│ \ │
└┼┘/ O , ./ . └ \ ┘ ──
""")] This makes font.py a little bit more verbose but it can make debugging much less confusing in the future. |
One thing I don't see in this PR but would also be good if you're going the route of making this a dual py2-py3 code base would be to add "from future import division" everywhere. This makes "/" yield a float and "//" do integer division. urwid does division in a few places where this distinction is important. Using the division future import will make sure that when there's a bug in the division, it shows up equally in both python2 and python3 (hopefully being detected faster). |
@abadger Good catch! I'm going to include those updates as well. |
1 similar comment
This looks good to me! |
@wardi any objections? Otherwise I'm merging this. |
2to3
outputwith_metaclass
fromsix
(to avoid adding entiresix
library as a dependency) and migrated all classes that had__metaclass__
attributetext_type
fromsix
text_types
xrange
raise
syntax etc.)print_function
from__future__
unicode_literals
from__future__
tofont.py
Outcome:
@wardi I'd like you to confirm that this can be merged. These changes are pretty massive and I want an additional confirmation from you to be extra sure that this can be merged.