Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'convention,': 0.09; 'warn': 0.09; 'cc:addr:python-list': 0.11; 'behavior,': 0.16; 'marco': 0.16; 'name)': 0.16; 'subject:class': 0.16; 'exception': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; '>>>': 0.22; '(in': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'refers': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'names.': 0.31; 'class': 0.32; 'subject:the': 0.34; 'could': 0.34; 'received:google.com': 0.35; 'there': 0.35; 'raising': 0.36; 'possible': 0.36; 'should': 0.36; 'two': 0.37; 'does': 0.39; 'name': 0.63; 'to:addr:gmail.com': 0.65; 'to,': 0.72; 'inform': 0.78; '100': 0.79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=oJQdpyB6VRe35a/FZ43kpZNiEjGnP04v9Y6TP3f3ZBs=; b=jDBLpfeBQxQyLZ+L/5JvZ2ain5bz6tKVHCVcuPS999c3dVhl9zevR30JvpRIwg9YPD n8Tv5jUQuWXd+L3BN2x/M1LNBwsYjg7N1je9lBygSTtLIe3YKDgRORiKASALDfgADlNH 6RSyuCXNrpJIeP5S/8eDGou9494LlHM/sOUcc+WUuABo++QEFqnGaJY49dzCNS2+cd24 RPtm6SU5cbQ1d6zk4TA4kJbIUOg4tfUBfEKQAckUXvtT59CMpY69hE0yaTsGMT+BfHEe HmNhHp1Ju9E9IPU9cDZ8e0vVISxjCQyPIp4W+Hdfjfyq8zeLXnU9qzCa/orV1YR0L1ze RP6g== X-Received: by 10.49.30.98 with SMTP id r2mr1204712qeh.80.1381230475206; Tue, 08 Oct 2013 04:07:55 -0700 (PDT) Sender: Ned Batchelder Date: Tue, 08 Oct 2013 07:07:53 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Marco Buttu Subject: Re: class-private names and the Zen of Python References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381230484 news.xs4all.nl 15868 [2001:888:2000:d::a6]:54379 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56386 On 10/8/13 6:13 AM, Marco Buttu wrote: > In the following case: > > >>> class Foo: > ... _Foo__a = 100 > ... __a = 33 > ... > >>> Foo._Foo__a > 33 > > I think this behavior, for a user who does not know the convention, > could be a surprise. Should be raising an exception (in order to > inform the user the transformation of the name __a have been replaced > an existing name) a possible --explicit-- alternative? You also get a "problem" if you do this: >>> class Foo: ... a = 100 ... a = 33 ... >>> Foo.a 33 Or for that matter: >>> a = 100 >>> a = 33 >>> a 33 There are lots of ways to change what value a name refers to, it's not an error to reassign names. Also, as Terry mentions, no one has ever assigned the two names you show, so why try to warn about it? --Ned.