Skip to content

Add support for tuple values on except clauses #1610

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 6 commits into from
Jun 3, 2016

Conversation

pdmccormick
Copy link
Contributor

Fixes issue #1590.

exs3 = (E2, E3)
try: pass
except exs3 as e3:
reveal_type(e3) # E: Revealed type is '__main__.E1'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, this is puzzling -- do you understand why it ends up being E1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

E1 is the nearest common ancestor to E2 and E3, so it is the most specific type that generalizes both.

@@ -1839,18 +1839,39 @@ def exception_type(self, n: Node) -> Type:
self.fail('Unsupported exception', n)
return AnyType()

def check_for_function_like_exception_type(self, type: Type, context: Context) -> Type:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because this can return None and not only an actual Type, let's annotate as Optional[Type]. PEP 484 specifies that types don't implicitly contain None; we don't quite yet implement that properly in mypy, so we don't catch this, but there's an active PR for it (#1562) and we will soon.

@gnprice gnprice merged commit e2ab99f into python:master Jun 3, 2016
@gnprice
Copy link
Collaborator

gnprice commented Jun 3, 2016

Thanks @pdmccormick for the fix! I also appreciate the negative diffstat on application code, and the positive diffstat on test code. :-)

pdmccormick added a commit to pdmccormick/mypy that referenced this pull request Jun 3, 2016
gnprice pushed a commit that referenced this pull request Jun 3, 2016
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