-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
exs3 = (E2, E3) | ||
try: pass | ||
except exs3 as e3: | ||
reveal_type(e3) # E: Revealed type is '__main__.E1' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
Thanks @pdmccormick for the fix! I also appreciate the negative diffstat on application code, and the positive diffstat on test code. :-) |
Follow-up to new handling from python#1610.
Fixes issue #1590.