Skip to content
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 3.4 support (with compatibility to 2.6 and 2.7) #64

Merged
merged 6 commits into from
Jul 26, 2015

Conversation

martinth
Copy link

I'm using this lib in one of my projects which I'm now porting to Python 3. While their are numerous PR they all doesn't seem to fit. Plus, they usually do something extra which make them hard to review.

I tried to address the issues you had:

The only thing I didn't address was Python 2.5 support which you said was more optional. I have also setup tox (like PR #62) so you can actually run the test on all three Python versions.

The only "real" change happened in readability/readability.py:87 where I simply opted to not check for the type but rather call split(). This made the conversion easier and is more pythonic.

As you can see, the changes are actually rather minimal and thus #63 directly compatible with this branch. If you see things you don't like pleases tell me. I'm really determined to bring Python 3 support and I won't stop nagging ;-)

Adds tox.ini to support running the tests on multiple versions. Adds
requirements.txt to support dependency installtion via pip.
Code now supports Python 2.6, 2.7 and 3.4. PYthon 3.3 isn't support
because of some issues with the parser and the difference between old and
new `raise` syntax.
@buriy
Copy link
Owner

buriy commented Apr 29, 2015

Currently I'm trying to merge the changes one by one in dev branch, yep no pull requests does a direct upgrade, but after v0.5 I released several days ago this should be more straightforward.
Thanks a lot -- I'll review your changes.

The only thing I didn't address was Python 2.5 support which you said was more optional.

Probably Python 2.5 support has to be removed: it doesn't like "from .htmls import blablabla" syntax (and python 3+ doesn't like "from htmls import blablabla" syntax, while 2.6 supports both, for 2.7 i'm not sure -- but older syntax broke for me with 2.7.9 not sure why).
Similarly, exceptions syntax is different (keyword "as") -- so I guess it will be hard to support both versions at once.

… `raise` syntax

Unfortunately the Python 2 `raise` syntax is not supported in Python 3.3 and not all 3.4.x versions so we deal with that by using conditional imports and a compatibility layer.
Since get_encoding() is only called when the input is *not* already unicode we need to declare the regexs as byte type so they continue to work in Python 3.
In PYthon 3 .decode() on bytes requires the name of the encoding to be a str type which means we have to convert the extracted encoding before we can use it.
buriy added a commit that referenced this pull request Jul 26, 2015
Added python 3 support (Supported: python 2.6, 2.7, 3.3, 3.4).
Thanks a lot to @martinth
@buriy buriy merged commit 1546587 into buriy:master Jul 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants