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

Porting to Python3 #31

Merged
merged 13 commits into from
Oct 19, 2018
Merged

Porting to Python3 #31

merged 13 commits into from
Oct 19, 2018

Conversation

ari3s
Copy link
Contributor

@ari3s ari3s commented Oct 19, 2018

It solves Python 3 compatibility issue (#13).

ari3s and others added 13 commits October 19, 2018 10:39
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]>
@vifactor vifactor merged commit 753d844 into vifactor:master Oct 19, 2018
@vifactor
Copy link
Owner

Awesome! thanks!

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