Nikita Sobolev <m...@sobolevn.me> added the comment:

Couple of thoughts.

1. You have to create quite complex structural "clone" of `Exception` for 
python-based `traceback`:

```python
    def test_non_exception_subtype(self):
        class RegularObject:
            __traceback__ = None
            __suppress_context__ = None
            __cause__ = None
            __context__ = None

            def __call__(self):
                return self  # we need it for `get_exception` to work

        obj = RegularObject()

        try:
            1 / 0
        except Exception as ex:
            obj.__traceback__ = ex.__traceback__

        err = self.get_report(obj, force=True)
        self.assertIn('1 / 0', err)  # passes
```

Is it really worth it? 

2. Removing `PyExceptionInstance_Check(value)` from 
https://github.com/python/cpython/blob/main/Modules/_testcapimodule.c#L3508-L3511
 does not really help that much, because we still need to call `PyErr_Display` 
below. Which assumes `value` to be `Exception`. 

There's no correct way of calling `print_exception()` directly as far as I 
understand. It is only called in `print_exception_recursive`, which in its 
order is called from:
- `print_chained` (called recursively from `print_exception_recursive`)
- `_PyErr_Display` -> `PyErrDisplay`

So, maybe instead we should change `print_exception` to not type check `value` 
again? 

Or we can cahnge some levels above. Like `PyErrDisplay`, it can return 
`TypeError` earlier if case `value` is invalid.

What do you think? :)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45615>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to