{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/2248","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/2248/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/2248/comments","events_url":"https://api.github.com/repos/python/mypy/issues/2248/events","html_url":"https://github.com/python/mypy/issues/2248","id":182915897,"number":2248,"title":"Assigning theoretically conflicting functions confuses mypy","user":{"login":"viraptor","id":188063,"avatar_url":"https://avatars.githubusercontent.com/u/188063?v=3","gravatar_id":"","url":"https://api.github.com/users/viraptor","html_url":"https://github.com/viraptor","followers_url":"https://api.github.com/users/viraptor/followers","following_url":"https://api.github.com/users/viraptor/following{/other_user}","gists_url":"https://api.github.com/users/viraptor/gists{/gist_id}","starred_url":"https://api.github.com/users/viraptor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viraptor/subscriptions","organizations_url":"https://api.github.com/users/viraptor/orgs","repos_url":"https://api.github.com/users/viraptor/repos","events_url":"https://api.github.com/users/viraptor/events{/privacy}","received_events_url":"https://api.github.com/users/viraptor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-13T22:05:58Z","updated_at":"2016-10-13T22:08:01Z","closed_at":null,"body":"The following code triggers mypy errors:\r\n```\r\n_ord = ord if str is bytes else lambda x: x\r\n\r\ndef f(s):\r\n    # type: (bytes) -> List[int]\r\n    return [_ord(c) for c in s]\r\n```\r\nOne is about `_ord`: `\"function\" not callable`\r\n\r\nAnother is about _ord itself: `Incompatible return value type (got \"Union[str, bytes, bytearray]\", expected \"int\")`\r\n\r\nThese may be 2 different issues actually, but I expected the following to happen. a) Based on the `--py2` flag, only one of the branches is considered and the type is obvious. b) Mypy should then know `_ord` is a callable function.\r\n\r\nIt seems like it already happens if `_ord` is written like this:\r\n```\r\ndef _ord(x):\r\n    if str is bytes:\r\n        return ord(x)\r\n    else:\r\n        return x\r\n```\r\nSpecifically there's no error about unknown `ord` in this case in py3 mode and no error about `return x` in py2 mode."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/253653130","html_url":"https://github.com/python/mypy/issues/2248#issuecomment-253653130","issue_url":"https://api.github.com/repos/python/mypy/issues/2248","id":253653130,"user":{"login":"viraptor","id":188063,"avatar_url":"https://avatars.githubusercontent.com/u/188063?v=3","gravatar_id":"","url":"https://api.github.com/users/viraptor","html_url":"https://github.com/viraptor","followers_url":"https://api.github.com/users/viraptor/followers","following_url":"https://api.github.com/users/viraptor/following{/other_user}","gists_url":"https://api.github.com/users/viraptor/gists{/gist_id}","starred_url":"https://api.github.com/users/viraptor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viraptor/subscriptions","organizations_url":"https://api.github.com/users/viraptor/orgs","repos_url":"https://api.github.com/users/viraptor/repos","events_url":"https://api.github.com/users/viraptor/events{/privacy}","received_events_url":"https://api.github.com/users/viraptor/received_events","type":"User","site_admin":false},"created_at":"2016-10-13T22:08:01Z","updated_at":"2016-10-13T22:08:01Z","body":"There's also no error in:\r\n```\r\nif str is bytes:\r\n    def _ord(x):\r\n        return ord(x)\r\nelse:\r\n    def _ord(x):\r\n        return x\r\n```\r\nso it looks like the ternary expression is introducing the problem."}}
{"actor":{"display_login":"viraptor"}}