Skip to content

Correctly type check redefinitions in try's else clause. #1429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2016
Merged

Conversation

gvanrossum
Copy link
Member

Fixes #1289. After a diff in the issue by @Brodie.

@@ -1758,9 +1758,6 @@ def visit_try_stmt(self, s: TryStmt) -> Type:
self.binder.try_frames.add(len(self.binder.frames) - 2)
self.accept(s.body)
self.binder.try_frames.remove(len(self.binder.frames) - 2)
if s.else_body:
self.accept(s.else_body)
self.breaking_out = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that self.breaking_out = False should be left here. I can try to come up with a test case, but if nothing breaks, I'd leave it.

@gvanrossum
Copy link
Member Author

OK, added it back. I was wondering about that; it's unclear even after scanning all the code exactly how this flag is used.

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 25, 2016

The exact semantics aren't entirely clean to me either. They way I understand it is that it will be true when statements following the current statement can't be reached -- for example, after a return statement. It gets trickier when there is non-trivial control flow such as within a try statement.

@JukkaL JukkaL merged commit 42b2faa into master Apr 25, 2016
@gvanrossum gvanrossum deleted the try-else-redef branch April 25, 2016 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants