Skip to content

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

Merged
JukkaL merged 2 commits into
masterfrom
try-else-redef
Apr 25, 2016
Merged

JukkaL merged 2 commits into
masterfrom
try-else-redef

Conversation

@gvanrossum

Copy link
Copy Markdown
Member

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

Comment thread mypy/checker.py
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
Copy Markdown
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
Copy Markdown
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

JukkaL commented Apr 25, 2016

Copy link
Copy Markdown
Collaborator

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