You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2023/03/09 17:23:00 UTC

[jira] [Commented] (IMPALA-11973) Add absolute_import and division __future__ imports to all python code

    [ https://issues.apache.org/jira/browse/IMPALA-11973?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17698505#comment-17698505 ] 

ASF subversion and git services commented on IMPALA-11973:
----------------------------------------------------------

Commit 82bd087fb1dcd2685ad1994364dd41182dcf840f in impala's branch refs/heads/master from Joe McDonnell
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=82bd087fb ]

IMPALA-11973: Add absolute_import, division to all eligible Python files

This takes steps to make Python 2 behave like Python 3 as
a way to flush out issues with running on Python 3. Specifically,
it handles two main differences:
 1. Python 3 requires absolute imports within packages. This
    can be emulated via "from __future__ import absolute_import"
 2. Python 3 changed division to "true" division that doesn't
    round to an integer. This can be emulated via
    "from __future__ import division"

This changes all Python files to add imports for absolute_import
and division. For completeness, this also includes print_function in the
import.

I scrutinized each old-division location and converted some locations
to use the integer division '//' operator if it needed an integer
result (e.g. for indices, counts of records, etc). Some code was also using
relative imports and needed to be adjusted to handle absolute_import.
This fixes all Pylint warnings about no-absolute-import and old-division,
and these warnings are now banned.

Testing:
 - Ran core tests

Change-Id: Idb0fcbd11f3e8791f5951c4944be44fb580e576b
Reviewed-on: http://gerrit.cloudera.org:8080/19588
Reviewed-by: Joe McDonnell <jo...@cloudera.com>
Tested-by: Joe McDonnell <jo...@cloudera.com>


> Add absolute_import and division __future__ imports to all python code
> ----------------------------------------------------------------------
>
>                 Key: IMPALA-11973
>                 URL: https://issues.apache.org/jira/browse/IMPALA-11973
>             Project: IMPALA
>          Issue Type: Sub-task
>          Components: Infrastructure
>    Affects Versions: Impala 4.3.0
>            Reporter: Joe McDonnell
>            Priority: Major
>
> 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscribe@impala.apache.org
For additional commands, e-mail: issues-all-help@impala.apache.org