Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-8508 Use Python 3 from toolchain for impala-python
  3. IMPALA-11973

Add absolute_import and division __future__ imports to all python code

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Impala 4.3.0
    • Impala 4.3.0
    • Infrastructure
    • None
    • ghx-label-7

    Description

      Python 3 changed the way imports work so that imports in modules need to be absolute.  To make our Python 2 behave like Python 3, we can add "from _future_ import absolute_import" to our python files.  More details here: https://python-future.org/compatible_idioms.html#imports-relative-to-a-package

      Python 3 also changed the default behavior of division to use float division in more circumstances (i.e. 1 / 2 is 0.5 rather than 0). To make Python 2 behave like Python 3, we can add "from _future_ import division" to our python files. Locations that need the old integer division can use '//'. More details here: https://python-future.org/compatible_idioms.html#division

      Since both involve adding an import to all files, doing them together reduces the disruption.

      These correspond to the no-absolute-import and old-division checks in Pylint. For old division, Pylint can point out locations that may need to be modified, and that needs to happen before adding the division import.

      Attachments

        Activity

          People

            joemcdonnell Joe McDonnell
            joemcdonnell Joe McDonnell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: