{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/1542","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/1542/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/1542/comments","events_url":"https://api.github.com/repos/python/mypy/issues/1542/events","html_url":"https://github.com/python/mypy/issues/1542","id":155303635,"number":1542,"title":"Infer type from \"assert isinstance()\" even if types aren't overlapping","user":{"login":"JukkaL","id":1107911,"avatar_url":"https://avatars.githubusercontent.com/u/1107911?v=3","gravatar_id":"","url":"https://api.github.com/users/JukkaL","html_url":"https://github.com/JukkaL","followers_url":"https://api.github.com/users/JukkaL/followers","following_url":"https://api.github.com/users/JukkaL/following{/other_user}","gists_url":"https://api.github.com/users/JukkaL/gists{/gist_id}","starred_url":"https://api.github.com/users/JukkaL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JukkaL/subscriptions","organizations_url":"https://api.github.com/users/JukkaL/orgs","repos_url":"https://api.github.com/users/JukkaL/repos","events_url":"https://api.github.com/users/JukkaL/events{/privacy}","received_events_url":"https://api.github.com/users/JukkaL/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-05-17T16:28:08Z","updated_at":"2016-05-18T11:14:34Z","closed_at":null,"body":"I think that we should infer `x` to be `str` in this example (this is based on a user issue):\r\n\r\n```\r\ndef f(x: int):\r\n    assert isinstance(x, str)\r\n    x + ''  # should be fine\r\n    x + 2  # should be an error\r\n```\r\n\r\nHere the rationale is that if the `isinstance` checks passes, `x` will be a string, not an integer.\r\n\r\nCurrently this doesn't work since mypy considers `int` and `str` to be non-overlapping. This is perhaps okay for `if isinstance()` (though perhaps only if variable has a type variable type with values such as `AnyStr`), but for `assert isinstance()` it doesn't make sense."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/219996154","html_url":"https://github.com/python/mypy/issues/1542#issuecomment-219996154","issue_url":"https://api.github.com/repos/python/mypy/issues/1542","id":219996154,"user":{"login":"rwbarton","id":22628,"avatar_url":"https://avatars.githubusercontent.com/u/22628?v=3","gravatar_id":"","url":"https://api.github.com/users/rwbarton","html_url":"https://github.com/rwbarton","followers_url":"https://api.github.com/users/rwbarton/followers","following_url":"https://api.github.com/users/rwbarton/following{/other_user}","gists_url":"https://api.github.com/users/rwbarton/gists{/gist_id}","starred_url":"https://api.github.com/users/rwbarton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwbarton/subscriptions","organizations_url":"https://api.github.com/users/rwbarton/orgs","repos_url":"https://api.github.com/users/rwbarton/repos","events_url":"https://api.github.com/users/rwbarton/events{/privacy}","received_events_url":"https://api.github.com/users/rwbarton/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T11:14:34Z","updated_at":"2016-05-18T11:14:34Z","body":"@JukkaL, according to my experiments, in the case above, mypy currently does not check the body of the `if` branch at all. (Even `reveal_type` is silently ignored.) Is that intentional? "}}