-
Notifications
You must be signed in to change notification settings - Fork 75.2k
Fix exception causes in session.py #37481
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
|
@cool-RR Thanks for this change! Am I right in thinking that this chaining syntax is only available in Python 3? Would @martinwicke Do we have a timeline for accepting changes that use Python 3 features? |
|
@mrry You're welcome, yes and yes. |
|
Great! Would you mind switching the PR to use |
a5b332a to
6209b5d
Compare
|
Yep, done. Just curious though, looking here it says that Python 3.5+ is required. What reason is there to avoid native Python 3 syntax like |
|
Thanks! Yes, I was hoping @martinwicke could clarify our policy on that. Even though we are no longer building PIP packages for Python 2.7, I believe we still have a few non-PIP users that are stuck on that version of Python, which prevents us from adopting new syntax (just yet). |
|
@mrry: I understand. I'll wait with fixing this problem in the entire project until after you've moved to Python 3 completely, so we could switch straight to |
|
@cool-RR Any update on this PR, please. Thanks! |
|
@gbaned See my last message. |
|
@mrry Any update on this PR, please. Thanks! |
|
@gbaned I moved this PR to ready state now. As far as I'm concerned we can move forward, just need confirmation that Python 2 support is dropped in TensorFlow. Here's a blog post I made where I explained my effort to push this Python 3 syntax in many open-source packages: https://blog.ram.rachum.com/post/621791438475296768/improving-python-exception-chaining-with There's now a PyLint rule that checks for this syntax. |
|
@cool-RR We are soooo close to being able to actually using Python3-only syntax. I'm re-running the tests and I will merge this if I can using the six as is. @ematejska FYI this would make a good test case whether we can really break Py2. |
|
@cool-RR Can you please check build failures. Thank you! |
6209b5d to
72276a1
Compare
|
@gbaned I rebased and pushed. It's been 4 hours and the CI hasn't started running yet. Is this normal? |
|
triggered it now |
|
@cool-RR Still, build failures are appearing, can you please fix those?. Thank you! |
|
Looks like you have a test |
|
Took a brief look, and seems like six changed the exception string, and you might need to update the test to reflect that. Here is the current error from CI Here is where the test was getting the name of the file exception was raised from (where the change needs to be made),
|
|
I'm gonna bow out, this is getting too complicated for me. |
I recently went over Matplotlib and Pandas, fixing a small mistake in the way that Python 3's exception chaining is used. If you're interested, I can do it here too. I've done it on just one file right now.
The mistake is this: In some parts of the code, an exception is being caught and replaced with a more user-friendly error. In these cases the syntax
raise new_error from old_errorneeds to be used.Python 3's exception chaining means it shows not only the traceback of the current exception, but that of the original exception (and possibly more.) This is regardless of
raise from. The usage ofraise fromtells Python to put a more accurate message between the tracebacks. Instead of this:You'll get this:
The first is inaccurate, because it signifies a bug in the exception-handling code itself, which is a separate situation than wrapping an exception.
Let me know what you think!