{"action":"created","issue":{"url":"https://api.github.com/repos/apple/swift/issues/18645","repository_url":"https://api.github.com/repos/apple/swift","labels_url":"https://api.github.com/repos/apple/swift/issues/18645/labels{/name}","comments_url":"https://api.github.com/repos/apple/swift/issues/18645/comments","events_url":"https://api.github.com/repos/apple/swift/issues/18645/events","html_url":"https://github.com/apple/swift/pull/18645","id":349693154,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA3NzQ5NjUx","number":18645,"title":"[DoNotMerge] Add Python 3 support.","user":{"login":"dan-zheng","id":5590046,"node_id":"MDQ6VXNlcjU1OTAwNDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"labels":[{"id":955546636,"node_id":"MDU6TGFiZWw5NTU1NDY2MzY=","url":"https://api.github.com/repos/apple/swift/labels/tensorflow","name":"tensorflow","color":"EF6C00","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-11T00:57:11Z","updated_at":"2018-08-16T19:12:48Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/apple/swift/pulls/18645","html_url":"https://github.com/apple/swift/pull/18645","diff_url":"https://github.com/apple/swift/pull/18645.diff","patch_url":"https://github.com/apple/swift/pull/18645.patch"},"body":"Note: This PR should not be merged until Python 3 support is discussed with the community.\r\n\r\n---\r\n\r\nThis approach for adding Python 3 support creates two pairs of CPython and Python modules:\r\n- `CPython2` and `Python2`\r\n- `CPython3` and `Python3`\r\n\r\n`Python2` and `Python3` compile the same source code,\r\n`stdilb/public/Python/Python.swift`.\r\n\r\nThis separation of the Python modules is not ideal for other modules that want\r\nto support both Python 2 and 3. Assuming pre-built packages will be released\r\nwith support for both Python 2 and 3, modules importing Python could be\r\ncompiled with either a `-DPYTHON2` or `-DPYTHON3` flag.\r\n\r\nExample:\r\n```swift\r\n// Default to Python 2.\r\n// Specify -DPYTHON3 to use Python 3.\r\n#if canImport(Python2)\r\n  import Python2\r\n#elseif canImport(Python3) && PYTHON3\r\n  import Python3\r\n#else\r\n#error(\"Toolchain does not support Python2 or Python3.\")\r\n#endif\r\n\r\n // Use same `PythonObject` APIs.\r\n```\r\n\r\nTodo:\r\n- Add Python 3 tests. It would be nice to avoid duplicating test files if possible, using lit configuration or double `RUN` lines."},"comment":{"url":"https://api.github.com/repos/apple/swift/issues/comments/413654182","html_url":"https://github.com/apple/swift/pull/18645#issuecomment-413654182","issue_url":"https://api.github.com/repos/apple/swift/issues/18645","id":413654182,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzY1NDE4Mg==","user":{"login":"dan-zheng","id":5590046,"node_id":"MDQ6VXNlcjU1OTAwNDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"created_at":"2018-08-16T19:12:48Z","updated_at":"2018-08-16T19:12:48Z","author_association":"COLLABORATOR","body":"Todo: make the `#if PYTHON2 ... #elseif PYTHON3` code in `Python.swift` smarter.\r\n\r\nFor symbols defined by Python 2 but not Python 3 (like `PyString_AsString`), we can rebind the equivalent Python 3 symbol to the same name.\r\n\r\nInstead of this:\r\n```swift\r\n#if PYTHON2\r\nlet pyStringCastFunction = PyString_AsString\r\n#elseif PYTHON3\r\nlet pyStringCastFunction = PyUnicode_AsUTF8\r\n#endif\r\n\r\nguard let cString = pyStringCastFunction(pyObject) else {\r\n```\r\n\r\nDo this:\r\n```swift\r\n#if PYTHON3\r\ninternal let PyString_AsString = PyUnicode_AsUTF8\r\n#endif\r\n\r\nguard let cString = PyString_AsString(pyObject) else {\r\n```"}}
{"actor":{"display_login":"dan-zheng"}}