Skip to content

Modernize Python 2 code to get ready for Python 3 - #220

Merged
harshildarji merged 4 commits into
TheAlgorithms:masterfrom
cclauss:modernize-python2-code
Dec 29, 2017
Merged

harshildarji merged 4 commits into
TheAlgorithms:masterfrom
cclauss:modernize-python2-code

Conversation

@cclauss

@cclauss cclauss commented Nov 25, 2017 •

Copy link
Copy Markdown
Member

Make the minimal, safe changes required to convert the repo's code to be syntax compatible with both Python 2 and Python 3. There are 5 undefined name issues below that would need to be fixed plus perhaps other issues to complete a port to Python 3 but this is a minimal, safe first step.

  • print() is a function in Python 3
  • from __future__ import absolute_import
  • fixed several raw_input() and xrange() references
  • fixed indentation errors

Run: futurize --stage1 -w **/*.py

See Stage 1: "safe" fixes http://python-future.org/automatic_conversion.html#stage-1-safe-fixes

$ python3 -m flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./data_structures/LinkedList/singly_LinkedList.py:14:13: F821 undefined name 'insert_tail'
            insert_tail(Head.next, data)
            ^
./data_structures/AVL/AVL.py:104:36: F821 undefined name 'right_child'
                        h_right = (right_child.right.height
                                   ^
./data_structures/AVL/AVL.py:105:41: F821 undefined name 'right_child'
                                    if (right_child.right is not None) else 0)
                                        ^
./data_structures/AVL/AVL.py:106:35: F821 undefined name 'right_child'
                        h_left = (right_child.left.height
                                  ^
./data_structures/AVL/AVL.py:107:41: F821 undefined name 'right_child'
                                    if (right_child.left is not None) else 0)
                                        ^
5     F821 undefined name 'right_child'
@harshildarji
harshildarji merged commit 09cc769 into TheAlgorithms:master Dec 29, 2017
@cclauss
cclauss deleted the modernize-python2-code branch December 29, 2017 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants