{"action":"closed","issue":{"url":"https://api.github.com/repos/google/yapf/issues/53","labels_url":"https://api.github.com/repos/google/yapf/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/google/yapf/issues/53/comments","events_url":"https://api.github.com/repos/google/yapf/issues/53/events","html_url":"https://github.com/google/yapf/issues/53","id":64923429,"number":53,"title":"Future imports aren't taken into account when checking syntax","user":{"login":"flyte","id":1153496,"avatar_url":"https://avatars.githubusercontent.com/u/1153496?v=3","gravatar_id":"","url":"https://api.github.com/users/flyte","html_url":"https://github.com/flyte","followers_url":"https://api.github.com/users/flyte/followers","following_url":"https://api.github.com/users/flyte/following{/other_user}","gists_url":"https://api.github.com/users/flyte/gists{/gist_id}","starred_url":"https://api.github.com/users/flyte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flyte/subscriptions","organizations_url":"https://api.github.com/users/flyte/orgs","repos_url":"https://api.github.com/users/flyte/repos","events_url":"https://api.github.com/users/flyte/events{/privacy}","received_events_url":"https://api.github.com/users/flyte/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-28T09:47:30Z","updated_at":"2015-03-30T16:39:03Z","closed_at":"2015-03-30T16:39:03Z","body":"This means that code like this will cause a SyntaxError:\r\n\r\n\tfrom __future__ import print_function\r\n\r\n\tdef call_my_function(the_function):\r\n\t    the_function(\"hi\")\r\n\r\n\tif __name__ == \"__main__\":\r\n\t    call_my_function(print)\r\n\r\nwith output/traceback like so:\r\n\r\n\tINTERNAL ERROR: \r\n\t    call_my_function(print)\r\n\tTraceback (most recent call last):\r\n\t  File \"/usr/lib/python2.7/runpy.py\", line 162, in _run_module_as_main\r\n\t    \"__main__\", fname, loader, pkg_name)\r\n\t  File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\r\n\t    exec code in run_globals\r\n\t  File \"/home/flyte/dev/yapf/yapf/__main__.py\", line 18, in <module>\r\n\t    sys.exit(yapf.main(sys.argv))\r\n\t  File \"yapf/__init__.py\", line 102, in main\r\n\t    print_diff=args.diff)\r\n\t  File \"yapf/__init__.py\", line 124, in FormatFiles\r\n\t    filename, style_config=style_config, lines=lines, print_diff=print_diff)\r\n\t  File \"yapf/yapflib/yapf_api.py\", line 68, in FormatFile\r\n\t    print_diff=print_diff)\r\n\t  File \"yapf/yapflib/yapf_api.py\", line 113, in FormatCode\r\n\t    reformatted_source = reformatter.Reformat(uwlines)\r\n\t  File \"yapf/yapflib/reformatter.py\", line 73, in Reformat\r\n\t    verifier.VerifyCode(formatted_code[-1])\r\n\t  File \"yapf/yapflib/verifier.py\", line 45, in VerifyCode\r\n\t    compile(normalized_code.encode('UTF-8'), '<string>', 'exec')\r\n\t  File \"<string>\", line 1\r\n\t    call_my_function(print)\r\n\t\t                     ^\r\n\tSyntaxError: invalid syntax\r\n\r\nThe problem is that each line is taken on its own merit without taking into account imports from __future__."}}