-
Notifications
You must be signed in to change notification settings - Fork 14
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
Porting to Python3 #31
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
All `print` statements are replaced with a `print()` function to be compatible with Python 3. In Python 3.x, the `end=' '` part will place a space after the displayed string instead of a newline. It requires to import `print_function` from `__future__` in Python 2 allowing to use the Python 3 style. Signed-off-by: Jan Beran <[email protected]>
Python 2 had separate `int` and `long` types for non-floating-point numbers. In Python 3, there is only `int` type, which mostly behaves like the `long` type in Python 2. The issue of missing `long` type is fixed by the usage of `past.builtins` module. Signed-off-by: Jan Beran <[email protected]>
The new literal syntax for sets is available and preferred in Python 3. It has been backported to Python 2.7. Signed-off-by: Jan Beran <[email protected]>
`isinstance` built-in function is preferred to compare types. Signed-off-by: Jan Beran <[email protected]>
In Python 3, imports can be either absolute or explicitly relative; implicit relative imports are forbidden. Signed-off-by: Jan Beran <[email protected]>
In Python 2, `filter(function, iterable)` returns a list and is equivalent to `[item for item in iterable if function(item)]` if function is not `None` and `[item for item in iterable if item]` if function is `None`. In Python 3, the function returns an iterator. The replacement of Python 2 `filter` function with a proper equivalent solves the Python 3 compatibility. Signed-off-by: Jan Beran <[email protected]>
`map()` built-in function returns a list on Python 2, but an iterator on Python 3. If the first argument to `map()` is a lambda function, then it is converted to an equivalent list comprehension. Signed-off-by: Jan Beran <[email protected]>
`six.iteritems()` replaces `dictionary.iteritems()` on Python 2 and `dictionary.items()` on Python 3. Signed-off-by: Jan Beran <[email protected]>
Many dictionary methods return lists in Python 2, but all of these methods return dynamic views in Python 3. In some context, the problem is solved by adding the `list()` function. Signed-off-by: Jan Beran <[email protected]>
`failobj` keyword does not exist in Python 3. The second parameter in `os.environ.get` call without any keyword means default that is used when the environment variable (the first parameter) does not exist. It is valid in both Python major versions. Signed-off-by: Jan Beran <[email protected]>
In Python 2 you could use the `str` type for both text and binary data which does not work in Python 3. The commit solves the differences to handle data properly and obtain finally the same output in both Python versions. Signed-off-by: Jan Beran <[email protected]>
Signed-off-by: Jan Beran <[email protected]>
Awesome! thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
It solves Python 3 compatibility issue (#13).