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

Make tests run on py3 #398

Merged
merged 48 commits into from
Jan 22, 2020
Merged

Make tests run on py3 #398

merged 48 commits into from
Jan 22, 2020

Conversation

julen
Copy link
Contributor

@julen julen commented Jan 21, 2020

This PR:

  • Makes tests run and pass on py3
  • Upgrades code to py3 constructs so that the previous point is possible
  • Drops support for py2

The codebase will definitely need more fixes because our current test coverage is around 80%.

Refs. #377.

This was used for live translation, a feature which ceased to exist long
time ago.
We need to do this because the file has been open in binary mode.
The `tostring` API only accepts strings, and this didn't break in py2
because `unicode` exists as a constructor. So while it didn't break, it
was encoding strings as ASCII.

Refs.
https://github.com/lxml/lxml/blob/6beef451a6690796d13fc3d2a19321434b880d16/src/lxml/html/__init__.py#L1790-L1793
int and long are now contained within int.
From the Python docs:
"for backward compatibility, the re.U flag still exists (as well as its
synonym re.UNICODE and its embedded counterpart (?u)), but these are
redundant in Python 3 since matches are Unicode by default for strings"
Previously the `__str__` method would perform the conversion step, and
the `serialize` method was relying on that behavior. When we merged
`__unicode__` and `__str__` methods though, that behavior ceased to
exist.

At the same time, we need to serialize to bytes (which was str in PY2),
so that change is needed too.
By default, files will be open in text mode under py3 (py2 was str,
hence bytes). In order to keep the previous behavior, we need to force
reading to bytes by specifying the extra 'b' flag to `open`.
`last_sync_revision` and `source_revision` can be `None`, and in such
cases comparisons and even logging would fail, because py3 is stricter
on what operations can be done across data types.
We convert filter/map to list comprehensions only when we actually need
a list. No changes have been made in cases where an iterator can be used
(e.g. for post-processing with `any`, `sorted`, `list`, or just
iterating).
Because now `keys()` and `items()` return iterators, in some cases we
need to convert them to lists.
The QuerySet returned by `values()` is not subscriptable, so we need to
convert it to a list.
The reported DB name string is different now.
Fixes linting issues and simplifies some patterns by removing unneeded
escaping.
@julen julen merged commit 6637ada into serge-community:py3 Jan 22, 2020
@julen julen deleted the py3-tests branch January 22, 2020 12:07
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.

1 participant