Hi all,

On Sat, 18 Jan 2020 14:27:23 +0200
Ram Rachum <r...@rachum.com> wrote:

> [...] In any case, the
> way Python chains exceptions when showing them is orthogonal to this
> proposed change. Python already displays the exceptions chained even
> if we don't use "raise from", the only thing that "raise from"
> changes is the text that Python puts between the 2 chained exceptions.
> 

Indeed. Well, almost: there is one more thing that addnig the `from`
changes, and that is the attributes on the exception (actually, it's
these attributes which really control the display): Without `from`, the
original exception is placed in a `__context__` attribute; with `from`,
it is placed in a `__cause__` attribute.

At first I thought this was a reason to object to this change -- I
thought code which catches exceptions and looks into their `__context__`
might break because of it. But as it turns out, `from` puts the
original exception on the `__cause__` in *addition* to `__context__`:

        In [8]: try:
           ...:     try:
           ...:         1/0
           ...:     except ZeroDivisionError as e:
           ...:         raise Exception("hi") from e
           ...: except Exception as ex:
           ...:     exc = ex
           ...: 

        In [10]: exc
        Out[10]: Exception('hi')

        In [13]: exc.__cause__ is exc.__context__
        Out[13]: True

So that is not a concern.

> Regarding automatically enforcing this format going forward: I looked
> at the list of Flake8 rules <https://www.flake8rules.com/> and
> couldn't find anything about it.
> 

Indeed, I don't think there can be -- it cannot be a style violation to
run into an error while handling another error...

Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/20200118170519.55c8f2e9.shai%40platonix.com.

Reply via email to