Preparations for python 3: issue warnings? -


i main guilty of reasonably large python package used internally in our organisation. in process of preparing package python3; code have control on myself quite doable - there many scripts "out in wild" break if/when organisation default interpreter yanked 3.x. typical situation follows:

some random script not have conrol over:

#!/usr/bin/env python    #   manipulating environment ...                          #   ... switch pick python3 import company.package   #   python3 safe.  ... print "this - fail hard" 

what (if possible) insert global warning directives in "company.package" code control - users can warning before global interpreter yanked python3. possible?

you can detect when script run in python 2.x , issue update warning this:

import warnings import sys  if sys.version_info < (3,0):     warnings.warn("company.package ported python 3 soon. make sure script py3k-safe!") 

unfortunately, there no way ensure python script run smoothly in python3, apart human inspection based on static analysis (e.g. 2to3 tool) and/or extensive unit testing.

edit: porting python 3 not matter of syntax, involves module renaming (like urllib, split, or cstringio) , conceptual changes (like bytearray/string distinction). there no import magic check that.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

javascript - Backbone.js getting target attribute -

html - Repeat image to extend header to fill screen -