Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: raise None Date: Fri, 1 Jan 2016 09:48:33 +1100 Lines: 62 Message-ID: References: <56847239$0$1590$c3e8da3$5496439d@news.astraweb.com> <5684842a$0$1596$c3e8da3$5496439d@news.astraweb.com> <5684aa1a$0$1602$c3e8da3$5496439d@news.astraweb.com> <56854b49$0$1615$c3e8da3$5496439d@news.astraweb.com> <85r3i2s776.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de SsR6+jKtLyRngOAoUwYFgwl6sQAadeqlivthQzSnDYBw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'debug': 0.04; 'bits': 0.07; 'feature.': 0.07; 'omit': 0.07; 'operand': 0.07; 'cc:addr:python-list': 0.09; 'benjamin': 0.09; 'caller.': 0.09; 'splitting': 0.09; 'subject:None': 0.09; 'throw': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'jan': 0.11; 'exception': 0.13; 'syntax': 0.13; 'def': 0.13; 'interpreter': 0.15; "'int'": 0.16; '+1.': 0.16; '2016': 0.16; 'advocating': 0.16; 'etc?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'itself).': 0.16; 'jython,': 0.16; 'list):': 0.16; 'raises.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; "steve's": 0.16; 'too?': 0.16; 'traceback.': 0.16; 'unsupported': 0.16; 'writer': 0.16; 'wrote:': 0.16; 'debugging': 0.18; 'integer': 0.18; '>>>': 0.20; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'extension': 0.20; 'java': 0.22; '"",': 0.22; 'advocate': 0.22; 'exceptions': 0.22; 'trying': 0.22; 'am,': 0.23; 'code.': 0.23; '(or': 0.23; '(most': 0.24; 'implemented': 0.24; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; 'figure': 0.27; 'point.': 0.27; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'actual': 0.28; 'etc).': 0.29; 'idea,': 0.29; 'obscure': 0.29; 'received:209.85.213.174': 0.29; 'raise': 0.29; "i'm": 0.30; 'code': 0.30; 'another': 0.32; "can't": 0.32; 'skip:_ 10': 0.32; 'knows': 0.32; 'useful': 0.33; 'class': 0.33; "he's": 0.33; 'hopefully': 0.33; 'int': 0.33; 'steven': 0.33; 'traceback': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'acceptable': 0.35; 'desirable': 0.35; 'happened': 0.35; 'tasks': 0.35; 'something': 0.35; 'but': 0.36; 'lines': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'difference': 0.38; 'received:209': 0.38; 'someone': 0.38; 'means': 0.39; 'why': 0.39; 'some': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'default': 0.61; 'information': 0.63; 'between': 0.65; 'benefit': 0.66; 'worth': 0.67; 'chrisa': 0.84; 'compare:': 0.84; 'oscar': 0.84; 'saying:': 0.84; 'type(s)': 0.84; 'to:none': 0.91; 'difficult,': 0.91; 'technique': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=V/r6Bs3JSRY6QydeyC2v0OC7BT5EyPXpT6N3yqWYwGk=; b=cZADY3uWXlVuoaTPrIkq+jdsU8K8KrbeiahYxHbLtQb/MF2/W6hAdErJGIiPlwXblT qmos/P8pMskd95xQZHymXW3NCPBpVcd2euDwBv+O172d2cCysy0y29r6BfwCmYL5COd6 hXsWRPVYuWrVev7K8UBF5SKx3rDQeen8G0Zfb1m4XNWhjiQ22i4keSgvPdDfq9SUFfM7 eW1iouP4gUNE1VqHUCV7XeTmO7aOroITiM2DXa79yfgzKkjoJypMSIHCaTRg2T3FnXiu OV0QxLHyeb5dunm0b8Y5Wsl0zhVBNOEir3RwvWADBORDSkau1C1MLkgnn5dxEOdRtUqy UuPg== X-Received: by 10.50.28.19 with SMTP id x19mr70438640igg.92.1451602113929; Thu, 31 Dec 2015 14:48:33 -0800 (PST) In-Reply-To: <85r3i2s776.fsf@benfinney.id.au> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101083 On Fri, Jan 1, 2016 at 7:18 AM, Ben Finney wrote: > Oscar Benjamin writes: > >> Exactly. The critical technique is looking at the traceback and >> splitting it between what's your code and what's someone else's. >> Hopefully you don't need to look at steves_library.py to figure out >> what you did wrong. However if you do need to look at Steve's code >> you're now stumped because he's hidden the actual line that raises. > > +1. > > As best I can tell, Steven is advocating a way to obscure information > from the traceback, on the assumption the writer of a library knows that > I don't want to see it. > > Given how very often such decisions make my debugging tasks needlessly > difficult, I'm not seeing how that's a desirable feature. What Steven's actually advocating is removing a difference between Python code and native code. Compare: >>> class Integer: ... def __add__(self, other): ... if isinstance(other, list): ... raise TypeError("unsupported operand type(s) for +: 'Integer' and 'list'") ... return 5 ... >>> 7 + [] Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'list' >>> Integer() + [] Traceback (most recent call last): File "", line 1, in File "", line 4, in __add__ TypeError: unsupported operand type(s) for +: 'Integer' and 'list' The default int type is implemented in native code (C in CPython, Java in Jython, etc). If the addition of an int and something else triggers TypeError, the last line in the traceback is the last line of Python, which is the caller. But since Integer is implemented in Python, it adds another line to the traceback. Would you advocate adding lines to the first traceback saying: File "longobject.c", line 3008, in long_add File "longobject.c", line 1425, in CHECK_BINOP etc? It might be useful to someone trying to debug an extension library (or the interpreter itself). Or if it's acceptable to omit the "uninteresting internals" from tracebacks, then why can't we declare that some bits of Python code are uninteresting, too? We already have the means of throwing exceptions into generators, which "pretends" that the exception happened at that point. Why can't we throw an exception out to the caller? I think it's a perfectly reasonable idea, albeit only a small benefit (and thus not worth heaps of new syntax or anything). ChrisA