Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'anyway.': 0.04; 'modify': 0.04; 'lines,': 0.05; 'variable,': 0.07; 'caching,': 0.09; 'subject:method': 0.09; '23,': 0.16; 'agree.': 0.16; 'copied,': 0.16; 'posted.': 0.16; 'shared.': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; 'code,': 0.23; '2015': 0.23; 'header:In-Reply- To:1': 0.24; 'tim': 0.24; 'external': 0.27; 'least': 0.27; 'defining': 0.27; 'message-id:@mail.gmail.com': 0.28; 'prints': 0.29; 'e.g.': 0.31; 'fixed': 0.31; 'code': 0.31; "can't": 0.32; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'instance': 0.35; 'expected': 0.35; 'problem.': 0.35; 'but': 0.36; 'being': 0.36; 'there': 0.36; 'two': 0.37; 'should': 0.37; 'client': 0.37; 'subject:: ': 0.37; 'tue,': 0.38; 'shared': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'why': 0.40; 'share': 0.60; 'even': 0.61; 'real': 0.61; 'state,': 0.66; 'consumer': 0.67; 'business': 0.69; 'to:name:python': 0.84; 'response,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=o9lYKlfzrHmeWkH5kgl/3pfaUzBF+eMWzD47rMgIF5A=; b=y+oq5DWA1fSrywg+emKrRY2/I0pBzd53PwwVawCN/3MYM92avrdZkJgoqzTaCvgl/F CuimtWmnaiMqePIzliAa2QNxM31O8Qkh16xV6x5ImQAZCL59u4pnVvM5jISBvL7iOhST f+vCKwA+gzyHakBBUzPPOVBbrkOdgGnju0ungnpqF//2uuIWvhNcPjb7o7T6snRM4F+F 4roC7z+HWnAePG9UTzYI2Er8oDm1Fw8zH0f1neQtR5GShxsRZgEk26+uItWDrKDWvMmr b7FOFcWj0DvW5nda98rZkkPNblEbayHrT+88XBv5PzNeOrKHlwLy8KcEYtY/RXFo2zu8 OsPQ== X-Received: by 10.170.195.205 with SMTP id m196mr4972150yke.39.1435087886104; Tue, 23 Jun 2015 12:31:26 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <109aafce-613c-4d6c-9f78-4bbe424f5901@googlegroups.com> References: <109aafce-613c-4d6c-9f78-4bbe424f5901@googlegroups.com> From: Ian Kelly Date: Tue, 23 Jun 2015 13:30:46 -0600 Subject: Re: method returns object reference To: Python Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435087895 news.xs4all.nl 2943 [2001:888:2000:d::a6]:51840 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93046 On Tue, Jun 23, 2015 at 12:32 PM, Tim wrote: > The code below prints the following two lines, showing how the 'newkey' i= s now inside the Client response, even though it was set in the worker. Th= is must be bad practice! In my real code, the response is no longer an ins= tance variable, which fixed the problem. It never had any business being bo= und to the client anyway. I agree. There may be reasons why the client would want to hold onto the response, e.g. caching, but there are none evident in the code you posted. What it *shouldn't* do if it's going to hold on to state like that is share it with external code without at least a contract defining allowed mutations. If the consumer can't reasonably be expected not to modify the shared state, then it should be copied, not shared.