Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; '(b)': 0.07; 'currently,': 0.09; 'objects,': 0.09; 'parameter': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '__future__': 0.16; 'defined,': 0.16; 'directive': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operator.': 0.16; 'other)': 0.16; 'wrote:': 0.18; 'module': 0.19; 'stack': 0.19; 'cc:addr:python.org': 0.22; '(a)': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'suggested': 0.26; 'header:In-Reply-To:1': 0.27; '(c)': 0.29; 'message-id:@mail.gmail.com': 0.30; 'getting': 0.31; 'bunch': 0.31; 'class': 0.32; 'running': 0.33; 'cases': 0.33; 'skip:_ 10': 0.34; 'maybe': 0.34; 'subject:the': 0.34; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'in.': 0.36; 'skip:o 20': 0.38; 'pm,': 0.38; 'problems.': 0.60; "you're": 0.61; 'places': 0.64; 'different': 0.65; 'determine': 0.67; 'do:': 0.91; '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=60EPRrFOq6/7FTnITKbJ2IZPAML96J+p/ZomjqbMsAs=; b=ZquVtleNElip/WyUBoeddQW2gRVotmmWGvs1AFaex5sPTvVN4tR13NOcc1KUB6EfoM ylgYdMUbj3T6y0nJm5b+hS2bBY/NmkitCrSkQsbQz/kVitPneS01xAgDX9h86aDM04rk aD+k4apkn95Np43Bqk5im3Di4H3rk4HfWKEzThKIYBK9eu47GVerYpID7BVlMKzPbLeA ixlW6/0bNTOk3mXZZXU8h9qk286PCgJhNgiEHFbM2Z4vB/jL/F2P57xCIuDNlmefbIXW /lEM5awfmkZEgQpRnRKYkVIsAPjaikthDi0ZM/JVJoZAoXBiDsibsAS7l5h0A9yy5IQQ GiDw== MIME-Version: 1.0 X-Received: by 10.68.247.6 with SMTP id ya6mr125165714pbc.45.1389061719995; Mon, 06 Jan 2014 18:28:39 -0800 (PST) In-Reply-To: References: Date: Tue, 7 Jan 2014 13:28:39 +1100 Subject: Re: the Gravity of Python 2 From: Chris Angelico Cc: "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: 1389061729 news.xs4all.nl 2881 [2001:888:2000:d::a6]:42004 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63402 On Tue, Jan 7, 2014 at 1:15 PM, Devin Jeanpierre wrote: > The other alternative is having + (etc.) do something different > depending on what module it's in. It's not hard to do: add a condition > to all places where Python automatically converts, and check the call > stack to see what module you're in. Currently, there are __add__ methods (and __radd__ but let's focus on __add__) on a bunch of objects, which determine what happens when you use the + operator. class Foo(str): def __add__(self, other): if isinstance(other, unicode): return self + other.encode("cp500") return str.__add__(self, other) What happens if you have the __future__ directive disabling autoencoding on (a) the module in which this class is defined, (b) the one in which the it was instantiated, (c) the one that actually uses the +? This is why I think it's getting magical. Far better to do this sort of change on a per-application basis - maybe with a warning parameter that you can enable when running your test suite, as has been suggested (and in many cases implemented) for other 2-vs-3 problems. ChrisA