Ongoing attempt at Python 3 support (progress towards #203) #242
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
These 6 commits hopefully prepare the ground for a full Python 2 / 3 compatible code base.
Rationale
The commits do the following:
futurebranch.futurizebest practices by running the automated--stage1and--stage2steps, keeping all tests green.futurizedoes not touch Cython files, sofunctools.reduceneeds to be manually imported.python2 -3signalled quite a few deprecated warnings concerning user-defined__eq__functions without an accompanying__hash__function. I have added hash support consistent with equality: if equality is on a tuple/list of class members, then the hashing will be on the same data structure (tuple or list of the data members ofself).python3 setup.py buildbecause of the new Python 3 class system (see this Q&A on StackOverflow).Status
python2 -3 nosetestsgives no warnings in code fromgambit, and only a handful about system code.python3 setup.py buildalso builds without errors.nosetestsin Python3 mode fails on all unit tests, mostly because ofbyte/strincompatibility.Guidance needed
cythoninterface of talking to the C++ code throughstd::stringorchar *. This will keep callers using Python2 happy, but requires converting Python3 unicode string literals tobyte, e.g. using a.encode('utf-8')member function call.char *strings fromc_str()member functions. When those talk to users, then they need to be marshalled through.decode(). Separating the internalc_str()calls from the ones bubbling up to the interface seems quite a bit of work.file()andopen()incompatibilities between Python2 and Python3. The way forward is to useopen()everywhere, with the appropriatebflags for byte stream reading.If you agree with the approach taken so far, I can try and plough ahead with the string and file issues. Merging the pull request would eventually be best done in one squashed commit, or piece meal, whatever your preference is.