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: zip function -> list(zip), itertools.izip -> zip() #9729

Merged
merged 5 commits into from Jun 14, 2019

Conversation

josephsl
Copy link
Collaborator

Hi,

Discovered through a series of failing unit tests:

Link to issue number:

None

Summary of the issue:

Python 2 and 3 zip functions have different behaviors: returns a list in Python 2 vs an iterator in Python 3.

Description of how this pull request fixes the issue:

Changed instances of zip() function call to list(zip), as well as rename itertools.izip to zip().

Steps:

  1. Grep "zip(" source.
  2. First, wrap language handler zip function inside a list call.
  3. Convert itertools.izip to zip and remove itertools import from IA1 mozilla text module.

Testing performed:

Tested in Python 2 and 3 interpreters.

Known issues with pull request:

None

Change log entry:

None

Behavior of zip() functoin has changed - returning a list in Python 2 versus being an iterator in Python 3. Because language handler/language list uses old zip function behavior, wrap this inside a list call.
@@ -628,7 +627,7 @@ def compareEndPoints(self, other, which):
otherAncs = self._getAncestors(otherTi, otherObj)
# Find the first common ancestor.
maxAncIndex = min(len(selfAncs), len(otherAncs)) - 1
for (selfAncTi, selfAncObj), (otherAncTi, otherAncObj) in itertools.izip(selfAncs[maxAncIndex::-1], otherAncs[maxAncIndex::-1]):
for (selfAncTi, selfAncObj), (otherAncTi, otherAncObj) in zip(selfAncs[maxAncIndex::-1], otherAncs[maxAncIndex::-1]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this line while at it

@@ -108,7 +108,9 @@ def getAvailableLanguages(presentational=False):
displayNames.append("%s, %s"%(desc,entry) if desc else entry)
#Prepare a zipped view of language codes and descriptions.
# #7284: especially for sorting by description.
langs = zip(locales,displayNames)
# #7105 (Py3 review required): Python 2 list 0> Python 3 iterator.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is necessary. Furthermore, it contains a typo.

…ndler, pslit lines in mozilla text iA2 objects.
@josephsl
Copy link
Collaborator Author

josephsl commented Jun 13, 2019 via email

@LeonarddeR LeonarddeR added this to In progress in Update NVDA to Python 3 via automation Jun 13, 2019
@michaelDCurran
Copy link
Member

@LeonarddeR are you still waiting for changes on this, or are you going to approve?

Update NVDA to Python 3 automation moved this from In progress to Reviewer approved Jun 14, 2019
Copy link
Collaborator

@LeonarddeR LeonarddeR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, go ahead.

@michaelDCurran michaelDCurran merged commit 8d63788 into nvaccess:threshold_py3_staging Jun 14, 2019
Update NVDA to Python 3 automation moved this from Reviewer approved to Done Jun 14, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Jun 14, 2019
@michaelDCurran
Copy link
Member

After merging this, setup.py failed as it found a syntax error in source\NVDAObjects\IAccessible\ia2TextMozilla.py, introduced by this pr. Due to a for loop being split across two lines.
I have manually fixed this in 5da17fd, which is now on threshold_py3_staging.
I appreciate that shorter line lengths are easier to read for some people, but I would suggest we back down on this a bit, especially with reviewing code for the Python3 transition. Not only was there this syntax error, but a lot of other code is having to be slightly rewritten, which really has nothing to do with Python3 and could introduce further bugs.

@LeonarddeR
Copy link
Collaborator

LeonarddeR commented Jun 14, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants