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
implement PEP 3134 exception reporting #47362
Comments
Traceback reporting needs to be altered to support exception chaining as |
Thinking about this, I realized that an exception can become its own (as for the exception reporting code, it will have to detect recursivity) >>> try: 1/0
... except Exception as e: raise e
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "<stdin>", line 1, in <module>
ZeroDivisionError: int division or modulo by zero
>>> e = sys.last_value
>>> e.__context__
ZeroDivisionError('int division or modulo by zero',)
>>> e.__context__ is e
True |
Does anyone know why there is the following test in pythonrun.c: Can PyErr_Display be called with something else than a PyException instance? |
Two other questions:
|
Here is a draft patch for those who want to take a look. (it works but the final cleanup is waiting for the API decisions |
Yet another question. There is a slight discrepancy between tracebacks With built-in reporting: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "f.py", line 22, in raise_cause
inner_raise_cause()
File "f.py", line 13, in inner_raise_cause
raise KeyError from e
KeyError With traceback.py: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "f.py", line 22, in raise_cause
inner_raise_cause()
File "f.py", line 13, in inner_raise_cause
raise KeyError from e
KeyError As you see, indentation of code lines is different. Should we harmonize |
|
Le dimanche 22 juin 2008 à 07:04 +0000, Adam Olsen a écrit :
You mean they should be detected when the exception is set? I was afraid (the "problem mentioned here" is already avoided in the patch, but the
I was not proposing to change the exception swallowing semantics, just |
On Sun, Jun 22, 2008 at 8:07 AM, Antoine Pitrou <report@bugs.python.org> wrote:
I meant only that trivial cycles should be detected. However, I This has placed a niggling doubt in my mind about chaining the
Ahh, harmless then, but to what benefit? Wouldn't the traceback |
Le dimanche 22 juin 2008 à 17:17 +0000, Adam Olsen a écrit :
Chaining the tracebacks rather than the exceptions loses important It is improbable to create such a cycle involuntarily, it means you
I don't know, I've never used that API, I just proposed returning that
I suppose built-in reporting is needed when reporting a grave error such But application code should use the traceback module rather than try to |
On Sun, Jun 22, 2008 at 1:04 PM, Antoine Pitrou <report@bugs.python.org> wrote:
I assumed each leg of the traceback would reference the relevant exception. Although.. this is effectively the same as creating a new exception
I'm not convinced.
For this behaviour, this is the most natural way to write it. |
Le dimanche 22 juin 2008 à 19:23 +0000, Adam Olsen a écrit :
I agree your example is not far-fetched. How about avoiding cycles for
It would be the reverse: first the fallback, then the re-raised |
On Sun, Jun 22, 2008 at 1:48 PM, Antoine Pitrou <report@bugs.python.org> wrote:
That's still O(n). I'm not so easily convinced it's cheap enough. And for that matter, I'm not convinced it's correct. The inner This would all be a lot easier if reraising always created a new |
Le dimanche 22 juin 2008 à 19:57 +0000, Adam Olsen a écrit :
O(n) when n will almost never be greater than 5 (and very often equal to
Yes, I've just thought about that, it's a bit annoying... We have to (just a small note: it's exception objects that are chained, not
How do you duplicate an instance of an user-defined exception? Using an
I don't think so, the exception can be referenced in an unknown number |
On Sun, Jun 22, 2008 at 2:20 PM, Antoine Pitrou <report@bugs.python.org> wrote:
Indeed.
The cycle is only created by broken behaviour. The more I think about
Passing in e.args is probably sufficient. All this would need to be
Can be, or will be? Only the most common behaviour needs to be optimized. |
Le dimanche 22 juin 2008 à 20:40 +0000, Adam Olsen a écrit :
I think it's very optimistic :-) Some exception objects can hold dynamic (yes, it is used an an exception: see "raise self" in the trap() method)
Well, the "most common behaviour" is a very short context chain, which |
On Sun, Jun 22, 2008 at 2:56 PM, Antoine Pitrou <report@bugs.python.org> wrote:
Failure doesn't have an args tuple and doesn't subclass Exception (or In short, if forcing Failure to be rewritten is the only consequence |
Le lundi 23 juin 2008 à 06:16 +0000, Adam Olsen a écrit :
Failure was only an example, I'm sure there are lots of other ones. The |
Here is the final patch. Features:
|
Potential reviewers, let's make life easier for you: |
I think there is a problem when the source file cannot be opened (a .pyc See bpo-3342 for a competing patch that corrects the indentation problem. |
Le vendredi 11 juillet 2008 à 12:12 +0000, Amaury Forgeot d'Arc a
Great! Do you plan to commit it soon or should I include it into my (and do you have other observations on the present patch?) |
I committed r64881, which invalidates your patch a bit :-| BTW, I don't like your comment "Can't be bothered to check all those |
Le vendredi 11 juillet 2008 à 22:18 +0000, Amaury Forgeot d'Arc a
Apparently you committed in trunk rather than py3k? Could you svnmerge
It's not my comment, it was already there. I agree it doesn't sound very
Well, as said above, I just kept the original method of doing things... |
Here is a new patch incorporating Amaury's better indentation fix for And for the code review junkies: http://codereview.appspot.com/2448 |
Antonine, do you have a patch address the review comments? |
Yes, although I've forgotten to upload it here - you will find it at PS: it is Antoine not Antonine :) |
Sorry, Antoine! The patch is in with r64965. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: