Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'cc:addr :python-list': 0.11; 'def': 0.12; '(none,': 0.16; '[1].': 0.16; 'api,': 0.16; 'cross.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none.': 0.16; 'troll': 0.16; 'url:linux': 0.16; 'exception': 0.16; 'wrote:': 0.18; "python's": 0.19; 'thu,': 0.19; 'value.': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; "haven't": 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'skip:p 30': 0.29; '[1]': 0.29; 'am,': 0.29; 'raise': 0.29; 'unix': 0.29; 'see,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '13,': 0.31; '>>>>': 0.31; 'slot': 0.31; 'fri,': 0.33; 'moment': 0.34; '(2)': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'otherwise.': 0.36; 'subject:?': 0.36; 'pm,': 0.38; 'ian': 0.60; 'url:3': 0.61; 'talking': 0.65; 'subject:. ': 0.67; 'mar': 0.68; 'statement,': 0.68; 'const': 0.84; 'fails,': 0.84; 'is!': 0.84; 'to:none': 0.92 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=Z0T/+BJxXwKbaE+LoIB66XOkCEcaxZJlTz1xIDh8DpU=; b=ZqyV9eS5053BTadBpRT6UETsHiosUtPw8U6TW+vVexBhrnQpqxlv6KkIYRUXuKWhDz 4bA5wO8jLEJwjHGaPx/+FBuwoszwW38qT5LLWNBlm8uPG+y3N9VNKkisogzO06YvC8np mYsK8DPbQuciKygp2f1OXWWZa57C6A8TKHWbayEXHVdNE0dzu1sTMNYNKLkK1xz4XSFn +xgT+n7FYLjXY3998Uxrm8fbUYLjUpqM/bIjkhp44WC1hvmUWfWdAoi5/CyFcfpyIJE9 5AY5Z7wcMFiVh65Rt44uD3v3KKVz2u2oPLwhg0qGaiJzfACXWX42tGkdEW7RYdwoWPkz JTSg== MIME-Version: 1.0 X-Received: by 10.68.171.193 with SMTP id aw1mr5587212pbc.117.1394756564043; Thu, 13 Mar 2014 17:22:44 -0700 (PDT) In-Reply-To: References: <53206e6a$0$2886$e4fe514c@news2.news.xs4all.nl> <53207d77$0$2886$e4fe514c@news2.news.xs4all.nl> <5320e8c9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87y50el1vf.fsf@elektro.pacujo.net> <5322420e$0$29994$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 14 Mar 2014 11:22:43 +1100 Subject: Re: Deep vs. shallow copy? From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394756567 news.xs4all.nl 2863 [2001:888:2000:d::a6]:32996 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68346 On Fri, Mar 14, 2014 at 11:08 AM, Ian Kelly wrote: > On Thu, Mar 13, 2014 at 5:55 PM, Chris Angelico wrote: >> I'm going to troll for a moment and give you a function that has no >> return value. >> >> def procedure(): >> raise Exception > >>>> import dis >>>> dis.dis(procedure) > 2 0 LOAD_GLOBAL 0 (Exception) > 3 RAISE_VARARGS 1 > 6 LOAD_CONST 0 (None) > 9 RETURN_VALUE That's a return value in the same way that exec() has a return value [1]. If somehow the raise fails, it'll return None. >>>> def get_procedure_return_value(): > ... """Returns the return value of procedure().""" > ... return procedure.__code__.co_consts[0] > ... >>>> print(get_procedure_return_value()) > None > > Look, there it is! Succeeds by coincidence. From what I can see, *every* CPython function has const slot 0 dedicated to None. At least, I haven't been able to do otherwise. >>> def function(x): return x*2+1 >>> import dis >>> dis.dis(function) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (2) 6 BINARY_MULTIPLY 7 LOAD_CONST 2 (1) 10 BINARY_ADD 11 RETURN_VALUE >>> function.__code__.co_consts (None, 2, 1) Your return value retriever would say it returns None still, but it doesn't. Trollbridge: you have to pay a troll to cross. ChrisA [1] I'm not talking about Python's 'exec' statement, but about the Unix exec() API, eg execlpe() - see http://linux.die.net/man/3/exec