{"action":"created","issue":{"url":"https://api.github.com/repos/apache/beam/issues/5053","repository_url":"https://api.github.com/repos/apache/beam","labels_url":"https://api.github.com/repos/apache/beam/issues/5053/labels{/name}","comments_url":"https://api.github.com/repos/apache/beam/issues/5053/comments","events_url":"https://api.github.com/repos/apache/beam/issues/5053/events","html_url":"https://github.com/apache/beam/pull/5053","id":312557236,"number":5053,"title":"[BEAM-3981] Futurize coders subpackage","user":{"login":"RobbeSneyders","id":20990866,"avatar_url":"https://avatars0.githubusercontent.com/u/20990866?v=4","gravatar_id":"","url":"https://api.github.com/users/RobbeSneyders","html_url":"https://github.com/RobbeSneyders","followers_url":"https://api.github.com/users/RobbeSneyders/followers","following_url":"https://api.github.com/users/RobbeSneyders/following{/other_user}","gists_url":"https://api.github.com/users/RobbeSneyders/gists{/gist_id}","starred_url":"https://api.github.com/users/RobbeSneyders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobbeSneyders/subscriptions","organizations_url":"https://api.github.com/users/RobbeSneyders/orgs","repos_url":"https://api.github.com/users/RobbeSneyders/repos","events_url":"https://api.github.com/users/RobbeSneyders/events{/privacy}","received_events_url":"https://api.github.com/users/RobbeSneyders/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-04-09T14:36:18Z","updated_at":"2018-04-13T15:27:11Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/apache/beam/pulls/5053","html_url":"https://github.com/apache/beam/pull/5053","diff_url":"https://github.com/apache/beam/pull/5053.diff","patch_url":"https://github.com/apache/beam/pull/5053.patch"},"body":"This pull request prepares the coders subpackage for Python 3 support. This pull request is the first of a series in which all subpackages will be updated using the same approach.\r\nThis approach has been documented [here](https://docs.google.com/document/d/1xDG0MWVlDKDPu_IW9gtMvxi2S9I0GB0VDTkPhjXT0nE/edit?usp=drive_web&ouid=104989467967390032603) and the WIP pull request can be found at #4990.\r\n\r\nThe used approach can be summarized as follows:\r\n\r\n- The future package provides tools to forward-port our code, while the six package focuses more on backporting. Whenever possible, we will therefore use the future package instead of the six package.\r\nThe future package provides backported Python 3 builtins, which can be used to write Python 3 style code with python 2 compatibility.\r\n\r\n- One of the biggest problems in porting python 2 code to python 3, is the changed handling of strings and bytes.\r\n\r\n  - The future package provides backported Python 3 `str` and `bytes` types. While these can be convenient to write Python 2/3 compatible code in end products, we don’t believe they are the right choice for Beam.\r\nThese backported types are new classes, subclassed from existing Python 2 builtins (e.g. `from future.builtins import int` imports the class `future.builtins.newint.newint`, which is a subclass op the Python 2 `long` type).\r\nWhile these new classes behave like the Python 3 types, they don’t give the same results when used in type checks, which are constantly used in beam (e.g. typecoders, typechecks, …)\r\n\r\n  - Instead, we propose to rewrite everything using the default `str` and `bytes` types. On Python 2, the `bytes` type is an alias for `str`. On Python 3, `str` is equivalent to Python 2 `unicode`.\r\nA consistent behaviour between Python 2/3 can be reached by using the `bytes` type whenever `str` behaviour is desired on Python 2 and `bytes` behaviour is desired on Python 3 (= bytes data).\r\nThe `unicode` type can be used whenever `unicode` behaviour is desired on Python 2 and `str` behaviour is desired on Python 3 (= text data). The `unicode` type is not available in Python 3, which can be solved by adding\r\n    ```\r\n    Try:\r\n      unicode           # pylint: disable=unicode-builtin\r\n    except NameError:\r\n      unicode = str\r\n    ```\r\n    at the top of the module.\r\n\r\n  - All string literals which represent `bytes`, should be marked as `b’’`. String literals representing `unicode` in test modules should not be marked u’’. These will automatically be interpreted as `unicode` literals in Python 3, but we still want to test for unmarked Python 2 code.\r\nDo not use the `from __future__ import unicode_literals` import since [its changes are too implicit and introduces a risk of subtle regressions on python 2](http://python-future.org/unicode_literals.html). \r\n\r\n- The used approach for the long / int types is equivalent to the `unicode` / `str` approach outlined above.\r\nThe `long` type is not available in Python 3, since `int` now has `long` behaviour. This can be solved by adding\r\n    ```\r\n    Try:\r\n      long          # pylint: disable=long-builtin\r\n    except NameError:\r\n      long = int\r\n    ```\r\n    at the top of the module.\r\n\r\n- Regression should be avoided as much as possible between the application of step 2 and step 3. This document proposes to take following measures to keep the probability of regression as low as possible:\r\n  - Add the following import to the top of every module:\r\n`from __future__ import absolute_import`\r\nWe can also add following imports to the top of every measure. This will ensures that no new code can be added using for instance the old python 2 division and adds consistency across modules. We would like to hear the community’s opinion on this.\r\n    ```\r\n    from __future__ import division\r\n    from __future__ import print_function\r\n    ```\r\n  - A new tox environment has been added which runs pylint --py3k to check for python 3 compatibility.\r\n\r\n@aaltay @charlesccychen "},"comment":{"url":"https://api.github.com/repos/apache/beam/issues/comments/381171611","html_url":"https://github.com/apache/beam/pull/5053#issuecomment-381171611","issue_url":"https://api.github.com/repos/apache/beam/issues/5053","id":381171611,"user":{"login":"tvalentyn","id":9408864,"avatar_url":"https://avatars3.githubusercontent.com/u/9408864?v=4","gravatar_id":"","url":"https://api.github.com/users/tvalentyn","html_url":"https://github.com/tvalentyn","followers_url":"https://api.github.com/users/tvalentyn/followers","following_url":"https://api.github.com/users/tvalentyn/following{/other_user}","gists_url":"https://api.github.com/users/tvalentyn/gists{/gist_id}","starred_url":"https://api.github.com/users/tvalentyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tvalentyn/subscriptions","organizations_url":"https://api.github.com/users/tvalentyn/orgs","repos_url":"https://api.github.com/users/tvalentyn/repos","events_url":"https://api.github.com/users/tvalentyn/events{/privacy}","received_events_url":"https://api.github.com/users/tvalentyn/received_events","type":"User","site_admin":false},"created_at":"2018-04-13T15:27:10Z","updated_at":"2018-04-13T15:27:10Z","author_association":"CONTRIBUTOR","body":"Run Python Dataflow ValidatesRunner"}}
{"actor":{"display_login":"tvalentyn"}}