alexmojaki / alexmojaki/stack_data
Differences in handling exceptions?
- Lenguaje dominante
- Python
- Estrellas
- 51
- Forks
- 23
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I observe differences when handling different kind of exceptions
In an interactive interpreter:
```python
>>> import stack_data.formatting
>>> stack_data.formatting.Formatter(show_variables=True).set_hook()
```
A simple exception:
```python
>>> a=1
>>> a/0
Traceback (most recent call last):
File "", line 1, in
ZeroDivisionError: division by zero
```
(By the way the variable "a" is not shown)
Another kind of exception:
```python
>>> 1+
Traceback (most recent call last):
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 67, in Formatter.set_hook..excepthook
66 | def excepthook(_etype, evalue, _tb):
--> 67 | self.print_exception(evalue)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_etype =
_tb = None
evalue = SyntaxError('invalid syntax', ('', 1, 3, '1+\n'))
self =
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 72, in Formatter.print_exception
71 | def print_exception(self, e=None, *, file=None):
--> 72 | self.print_lines(self.format_exception(e), file=file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e = SyntaxError('invalid syntax', ('', 1, 3, '1+\n'))
file = None
self =
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 83, in Formatter.print_lines
80 | def print_lines(self, lines, *, file=None):
81 | if file is None:
82 | file = sys.stderr
--> 83 | for line in lines:
84 | print(line, file=file, end="")
file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
file is None = False
line = ' 84 | print(line, file=file, end="")\n'
lines =
self =
sys.stderr = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
File "/tmp/plop-2681655/lib/python3.9/site-packages/stack_data/formatting.py", line 100, in Formatter.format_exception
96 | yield from self.format_exception(e.__context__)
97 | yield traceback._context_message
99 | yield 'Traceback (most recent call last):\n'
--> 100 | yield from self.format_stack(e.__traceback__)
101 | yield from traceback.format_exception_only(type(e), e)
e = SyntaxError('invalid syntax', ('', 1, 3, '1+\n'))
e is None = False
e.__suppress_context__ = False
not e.__suppress_context__ = True
self =
self.chain = True
traceback._cause_message = '\nThe above exception was the direct cause of the following exception:\n\n'
traceback._context_message = '\nDuring handling of the above exception, another exception occurred:\n\n'
type(e) =
File "", line 1
1+
^
SyntaxError: invalid syntax
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.