Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4a.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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'else:': 0.03; 'argument': 0.05; 'assignment': 0.07; 'augmented': 0.09; '18:13,': 0.16; 'ast': 0.16; 'costs.': 0.16; 'get,': 0.16; 'locating': 0.16; 'reraise': 0.16; 'exception': 0.16; 'ignore': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'import': 0.22; 'saying': 0.22; 'to:name:python-list@python.org': 0.22; 'error': 0.23; 'certainly': 0.24; 'text.': 0.24; 'skip:" 30': 0.26; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'raise': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; 'closer': 0.31; 'though.': 0.31; 'yes.': 0.31; 'probably': 0.32; 'skip:c 30': 0.32; 'totally': 0.33; "i'd": 0.34; 'could': 0.34; 'possible.': 0.35; 'something': 0.35; 'done.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'doing': 0.36; 'possible': 0.36; 'should': 0.36; 'implement': 0.38; 'to:addr :python-list': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'around.': 0.60; 'catch': 0.60; 'hope': 0.61; 'lower': 0.61; 'march': 0.61; 'matter': 0.61; "you're": 0.61; 'more': 0.64; 'benefit': 0.68; 'home.': 0.72; 'costly': 0.84; 'done;': 0.84; 'valid,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=D4Wzrh1OF/856hzLu4j9i5gyboOciDmfrjRNqTssRHY=; b=AKPITMoc5zMXiU+9Ng8Ofr4LYaDfMiJYrJ3yJlUju+9e+Gzn3rJjSmfNueZuJ2Jj4J EjTmQMPUnilQT7U39/FRveCQSWKiVYIMX+jAZt27l0+rSaTcxUCCiWwrDusXbqe7UMH+ IpoGtf38wKuf3Tp/xQMEoKhHxIfLNAJUby3kEO/QEfXcgNLY9mh2bTWDHJaV0F3ReMhI P8J+IVv9h9CgU7fdoYQCLasyS8XBtj0BXjgTPTjGGlHBA7j4ML2vRZPRma6IWA2vFtsH 8ofQJaLTWDurlwqJsw0r0iePqZTl3l/vPpCj9Tj20pDbuNpt418hwM9IXSgHTFhVEo11 /UFw== X-Received: by 10.112.159.234 with SMTP id xf10mr6832460lbb.28.1394395108396; Sun, 09 Mar 2014 12:58:28 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: References: From: Joshua Landau Date: Sun, 9 Mar 2014 19:57:48 +0000 X-Google-Sender-Auth: nF3LIsyRNICxG-qUzmmsWscL5F8 Subject: Re: Tuples and immutability To: "python-list@python.org" 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394395115 news.xs4all.nl 2908 [2001:888:2000:d::a6]:35208 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68089 On 9 March 2014 18:13, Chris Angelico wrote: > I think I see what you're saying here. But ignore "top-level"; this > should just be a part of the exception message, no matter what. I don't think I was clear, but yes. That. > What you're saying is that this should notice that it's doing an > augmented assignment and give some more text. This can be done; all > you need to do is catch the error and reraise it with more info: > [...] > Now you can look at writing an import hook that does an AST transform, > locating every instance of item assignment and wrapping it like that. > It's certainly possible. I'm not sure how much benefit you'd get, but > it could be done. I would probably implement it closer to home. Inside tuple.__getitem__, there would be something like if context_is_augmented_assignment(): raise TypeError(message+warning) else: raise TypeError(message) which would have much lower technical costs. It does depend on how costly "context_is_augmented_assignment" is, though. A speed argument is totally valid, but I'd hope it's possible to work around.