-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Now typecheckes traceback
in raise e, msg, traceback
on py2
#11289
Now typecheckes traceback
in raise e, msg, traceback
on py2
#11289
Conversation
I found several other corner-cases, which I want to cover later today. |
Corner cases:
class Old:
pass
raise Old
# Traceback (most recent call last):
# File "Main.py", line 4, in <module>
# raise Old
# __main__.Old: <__main__.Old instance at 0x14ada04a35f0> I don't think that we should ever support this. First of all,
e = (Exception, 2, 3, 4, 5, 6, 7, 8) # or `Exception('a')`
raise e
# Traceback (most recent call last):
# File "Main.py", line 8, in <module>
# raise e
# Exception This is something we can clearly support. I will add this to this PR.
e = Exception('a') # Or `(Exception('a'),)`
raise e, 'b'
# TypeError: instance exception may not have a separate value I will add a check for that as well.
class My(Exception):
def __init__(self, start, finish):
pass
raise My, 1 # should raise Currently, we don't support this. But in runtime if fails:
We need to check this similarly to Python3. |
This seems fine, but honestly it doesn't feel that valuable to fix arcane aspects of Python 2 raise syntax. Python 2 support is a low priority already and we may drop support at some point. If this solves problems in your codebase, though, I'm happy to review and merge it. |
Not production code, fortunately 🙂
Sure thing! Right now it would be even easier: because all python2 related code for this feature now lives in a separate protected function with @JelleZijlstra it's now ready to be reviewed. |
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.
Thanks! I have two small comments.
|
||
# Plain 'raise' is a valid statement. | ||
expr: Optional[Expression] | ||
from_expr: Optional[Expression] | ||
# Is set when python2 has `raise exc, msg, traceback`. | ||
legacy_mode: bool | ||
|
||
def __init__(self, expr: Optional[Expression], from_expr: Optional[Expression]) -> None: |
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.
Why not make it a constructor argument?
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 we only use it in fastparse2
and nowhere else. It would be easier to remove one day.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Thanks! 🎉 |
python#11289)" (python#11743) This reverts commit c22beb4. See python#11742 for context.
No description provided.