Re: Use "raise from" where appropriate, all over the codebase

2020-02-08 Thread Ram Rachum
FYI: I opened a thread on Python-ideas where we continued the discussion on my `raise as` proposal, Shai's proposal, etc.: https://mail.python.org/archives/list/python-id...@python.org/thread/KM7NRNFZHALOBKJUXVYQL2SLDP3MAANW/ On Fri, Feb 7, 2020 at 1:16 PM Ram Rachum wrote: > > > On Fri, Feb 7,

Re: Use "raise from" where appropriate, all over the codebase

2020-02-07 Thread Carlton Gibson
Maybe... it's still more verbose for no gain as I see it. I think the default implicit chaining is correct in the default case. It's only if you want to adjust that (or suppress is with `from None`) that the extra clause comes in handy. I think using the default unless there's a reason not to

Re: Use "raise from" where appropriate, all over the codebase

2020-02-07 Thread Ram Rachum
On Fri, Feb 7, 2020 at 12:23 PM Carlton Gibson wrote: > > I'm basing it on the fact that Carlton approved this PR for the style > guide: https://github.com/django/django/pull/12350 > > No. I don't think we should merge that change. (It's "approved" qua itself > before reviewing, and dependent on

Re: Use "raise from" where appropriate, all over the codebase

2020-02-07 Thread Carlton Gibson
> I'm basing it on the fact that Carlton approved this PR for the style guide: https://github.com/django/django/pull/12350 No. I don't think we should merge that change. (It's "approved" qua itself before reviewing, and dependent on the main PR.) To be clear. I think the default implicit

Re: Use "raise from" where appropriate, all over the codebase

2020-02-07 Thread Ram Rachum
On Fri, Feb 7, 2020 at 12:27 AM Aymeric Augustin < aymeric.augus...@polytechnique.org> wrote: > Hello Ram, > > On 6 Feb 2020, at 19:08, Ram Rachum wrote: > > In other words, "raise from" is the inevitable future, it's just that > we're not in a rush to get there. > > > I'm not sure how you came

Re: Use "raise from" where appropriate, all over the codebase

2020-02-06 Thread Ryan Hiebert
> > I think the conclusion should be to ask for a change in Python, not > Django. The rule "if an exception is raised explicitly from an except > clause then it is considered raised-from" seems simple enough to me. > I really like that. It makes perfect sense, and I can't think of a case where

Re: Use "raise from" where appropriate, all over the codebase

2020-02-06 Thread Shai Berger
On Thu, 6 Feb 2020 20:08:28 +0200 Ram Rachum wrote: > > If I understand correctly, you both agree that using "raise from" in > this context is better than using plain raise, just that the benefits > are not worth the price of a bulk update to Django. In other words, > "raise from" is the

Re: Use "raise from" where appropriate, all over the codebase

2020-02-06 Thread Aymeric Augustin
Hello Ram, > On 6 Feb 2020, at 19:08, Ram Rachum wrote: > > In other words, "raise from" is the inevitable future, it's just that we're > not in a rush to get there. I'm not sure how you came to this conclusion; I'm not seeing this in Carlton's and Mariusz' answers. Carlton only said that

Re: Use "raise from" where appropriate, all over the codebase

2020-02-06 Thread Ram Rachum
Hi guys, I'm disappointed that you're against this change... But I understand that you have a different perspective. Here's my last-ditch effort to convince you. If I understand correctly, you both agree that using "raise from" in this context is better than using plain raise, just that the

Re: Use "raise from" where appropriate, all over the codebase

2020-02-06 Thread Mariusz Felisiak
I agree with Carlton, I don't see much (if any) value in the bulk update. Best, Mariusz -- 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,

Re: Use "raise from" where appropriate, all over the codebase

2020-02-06 Thread Carlton Gibson
> +1 on chaining exceptions. I think the information is useful. Absolutely. But exceptions are **already** chained, regardless of whether we use the `from` syntax. Without the from clause exceptions are "implicitly" chained. With the from claus it's "explicit". Just the same tracebacks are

Re: Use "raise from" where appropriate, all over the codebase

2020-01-22 Thread Ram Rachum
I made a pull request for the style guide if anyone would like to review: https://github.com/django/django/pull/12350 On Mon, Jan 20, 2020 at 6:05 PM Ram Rachum wrote: > Jon: That's awesome! I also liked R101. I didn't think of that. > > Adam: I thought so too, but after going over dozens of

Re: Use "raise from" where appropriate, all over the codebase

2020-01-20 Thread Ram Rachum
Jon: That's awesome! I also liked R101. I didn't think of that. Adam: I thought so too, but after going over dozens of R100 cases, I didn't find even one where a raise without "from" inside an except clause was justified. I challenge you to show me even one such example. On Mon, Jan 20, 2020 at

Re: Use "raise from" where appropriate, all over the codebase

2020-01-20 Thread Adam Johnson
Nice work Jon. I don't think we can generally apply R100 though - thre are definitely cases where "raise" inside an exception handler is not *caused* by the other exception - but maybe that's a sign refactoring is needed. On Sun, 19 Jan 2020 at 22:52, Jon Dufresne wrote: > > > I think it's rare

Re: Use "raise from" where appropriate, all over the codebase

2020-01-19 Thread Jon Dufresne
> > I think it's rare enough that personally, I would have liked to have a > > Flake8 / PyLint rule like that enforces it, and allow ignoring it > > with a comment. (As much as I hate Lint ignore comments.) > > That makes sense. And you know, flake8 supports plugins... a couple of > web searches

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Adam Johnson
> > I would like to make the point that chained exceptions might be slightly > annoying when displayed via console output, as you see the inner exception > first and have to scroll up to see the exception you actually have to > handle. Just coming back to this, Tom it's not quite true. Yes you

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Shai Berger
On Sat, 18 Jan 2020 17:18:41 +0200 Ram Rachum wrote: > On Sat, Jan 18, 2020 at 5:05 PM Shai Berger wrote: > > > > Regarding automatically enforcing this format going forward: I > > > looked at the list of Flake8 rules > > > and couldn't find anything about it. >

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Jon Dufresne
+1 on chaining exceptions. I think the information is useful. > Is there anything we can do to control the way python displays them? I don't think we should do anything non-standard to display exceptions. Over time, Python programmers have become accustomed to how these exceptions are displayed.

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Ram Rachum
On Sat, Jan 18, 2020 at 5:05 PM Shai Berger wrote: > [snip] But as it turns out, `from` puts the > original exception on the `__cause__` in *addition* to `__context__`: > > [snip] > So that is not a concern. > Awesome! I did not know that. > > Regarding automatically enforcing this format

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Shai Berger
Hi all, On Sat, 18 Jan 2020 14:27:23 +0200 Ram Rachum 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" >

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Ram Rachum
Hi Uri, All the files were edited manually by me. I used a crude regex to find the relevant locations: "except .{3,100}raise" I bet that there are a few cases that my regex didn't cover, but it probably covered 90%, so we can first decide whether we want this change, and later worry about the

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread אורי
Ram, I noticed that 100 files changed in this commit. Did you edit each file manually before you committed, or was it some script doing it for you? If it was a script or program, can I see it? Uri. אורי u...@speedy.net On Sat, Jan 18, 2020 at 11:55 AM Ram Rachum wrote: > Hi guys, > > I

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Ram Rachum
Hi Tom and Adam, I do agree that Python's chained exceptions can be confusing. Of course, when you really need that exception information to troubleshoot something, it's an absolute godsend. In any case, the way Python chains exceptions when showing them is orthogonal to this proposed change.

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Adam Johnson
Agree with Tom here. Is there anything we can do to control the way python displays them? And how would we ensure the format is kept going forwards? Is there a flake8 rule/plugin we could activate to enforce it? On Sat, 18 Jan 2020 at 10:23, Tom Forbes wrote: > I agree with this change from a

Re: Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Tom Forbes
I agree with this change from a correctness standpoint but I would like to make the point that chained exceptions might be slightly annoying when displayed via console output, as you see the inner exception first and have to scroll up to see the exception you actually have to handle. Tom > On

Use "raise from" where appropriate, all over the codebase

2020-01-18 Thread Ram Rachum
Hi guys, I recently made a big ticket/PR to Django, and Shai Berger told me I should first talk about it in this mailing list. This is the ticket: https://code.djangoproject.com/ticket/31177 and its PR: https://github.com/django/django/pull/12339 It's a generalization of this ticket that I