{"action":"closed","issue":{"url":"https://api.github.com/repos/JukkaL/mypy/issues/1040","labels_url":"https://api.github.com/repos/JukkaL/mypy/issues/1040/labels{/name}","comments_url":"https://api.github.com/repos/JukkaL/mypy/issues/1040/comments","events_url":"https://api.github.com/repos/JukkaL/mypy/issues/1040/events","html_url":"https://github.com/JukkaL/mypy/issues/1040","id":120095450,"number":1040,"title":"Potential of raise causes variables to be undefined","user":{"login":"gvanrossum","id":2894642,"avatar_url":"https://avatars.githubusercontent.com/u/2894642?v=3","gravatar_id":"","url":"https://api.github.com/users/gvanrossum","html_url":"https://github.com/gvanrossum","followers_url":"https://api.github.com/users/gvanrossum/followers","following_url":"https://api.github.com/users/gvanrossum/following{/other_user}","gists_url":"https://api.github.com/users/gvanrossum/gists{/gist_id}","starred_url":"https://api.github.com/users/gvanrossum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gvanrossum/subscriptions","organizations_url":"https://api.github.com/users/gvanrossum/orgs","repos_url":"https://api.github.com/users/gvanrossum/repos","events_url":"https://api.github.com/users/gvanrossum/events{/privacy}","received_events_url":"https://api.github.com/users/gvanrossum/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JukkaL/mypy/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-03T05:14:20Z","updated_at":"2015-12-04T05:02:24Z","closed_at":"2015-12-04T05:02:24Z","body":"Not sure how to say this. Example code:\r\n```\r\nclass C:\r\n    def foo(self) -> None:\r\n        try:\r\n            pass\r\n        except:\r\n            raise\r\n        self.x = 42\r\n    def bar(self) -> int:\r\n        return self.x\r\n```\r\nIn bar() we get a complaint about the type of self.x:\r\n```\r\n/Users/guido/mypy_tests/mypy_raise.py: note: In member \"bar\" of class \"C\":\r\n/Users/guido/mypy_tests/mypy_raise.py:9: error: Cannot determine type of 'x'\r\n```\r\nIf we remove the try/except in foo() the error goes away. Apparently any reachable occurrence of `raise` before `self.x` is assigned causes mypy to skip/ignore the definition. But the presence of other statements that *could* fail does not. (In the real-world example where I hit this, the definition was in an `__init__()` that had an `except` clause with `raise` in it before the definition.)"}}