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

Modernize Python 2 code to get ready for Python 3 #410

Closed
wants to merge 2 commits into from

Conversation

@cclauss
Copy link

commented Jun 6, 2019

Use print() function in both Python 2 and Python 3

  • Legacy print statements are syntax errors in Python 3 but print() function works as expected in both Python 2 and Python 3.

Old style exceptions --> new style for Python 3

  • Old style exceptions are syntax errors in Python 3 but new style exceptions work as expected in both Python 2 and Python 3.
Modernize Python 2 code to get ready for Python 3
* Use __print()__ function in both Python 2 and Python 3
    * Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
* Old style exceptions --> new style for Python 3
    * Old style exceptions are syntax errors in Python 3 but new style exceptions work as expected in both Python 2 and Python 3.
raster/scripts/python/rtrowdump.py Outdated Show resolved Hide resolved
@@ -26,15 +26,16 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
###############################################################################
from __future__ import print_function

This comment has been minimized.

Copy link
@mwtoews

mwtoews Jun 6, 2019

This import and similar below are not needed, as I don't see any use of print() function as documented.

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 6, 2019

Author

This directive will prevent compatibility regressions by changing Python 2 so that it is a syntax error to use legacy print statements. This prevents Python 2 developers from breaking Python 3 compatibility.

$ python2 -c "from __future__ import print_function ; print 'hi'"

This comment has been minimized.

Copy link
@mwtoews

mwtoews Jun 6, 2019

these imports are fine and can stay. Python 2 will not be maintained past 2020, so I won't expect too many Python 2 developers down the road.

@mwtoews
mwtoews approved these changes Jun 6, 2019
cclauss added a commit to cclauss/postgis that referenced this pull request Jun 6, 2019
Travis CI: Lint Python code for syntax errors
These test will fail until postgis#410 (or similar) is landed.

Also the __sudo:__ tag is now deprecated in Travis CI: https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration

"_If you currently specify __sudo:__ in your __.travis.yml__, we recommend removing that configuration_"

@Komzpa Komzpa self-requested a review Jun 6, 2019

@dbaston
dbaston approved these changes Jun 6, 2019
@pramsey

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

I'm on expert, but seems fine to me. Going to apply?

@strk strk closed this in 0b016a7 Jun 9, 2019

@cclauss cclauss deleted the cclauss:modernize-Python-2-codes branch Jun 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.