Skip to content
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

Handle raise Exception(), None on Python2.7 #11786

Merged
merged 4 commits into from
Feb 22, 2022
Merged

Handle raise Exception(), None on Python2.7 #11786

merged 4 commits into from
Feb 22, 2022

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Dec 18, 2021

I hope that this time we've covered everything 🙂

Closes #11742
Related #11743
Related #11289
Related #11700

mypy/checker.py Outdated
Comment on lines 3552 to 3556
if (len(typ.items) >= 2
and isinstance(get_proper_type(typ.items[1]), NoneType)):
expected_type = exc_inst_or_type
else:
expected_type = TypeType(exc_type)
Copy link
Member Author

Choose a reason for hiding this comment

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

This part has changed compared to the original PR, CC @JukkaL

@sobolevn
Copy link
Member Author

Note that raise Exception(), None, traceback also works:

import sys

t = None
try:
    1 / 0
except ZeroDivisionError as e:
    _, _, t = sys.exc_info()

print('done', type(t))
raise Exception(), None, t

Try it online: https://paiza.io/projects/e/fX6oV85YpCzoXIWv5h-pmw

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks, this is very carefully done! Note that I'm planning to announce a Python 2 feature freeze very soon, but this may still be useful for those that are still using Python 2.

@JukkaL JukkaL merged commit 7143424 into python:master Feb 22, 2022
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.

False positive with Python 2 old-style raise statement
2 participants