Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63402 > unrolled thread

Re: the Gravity of Python 2

Started byChris Angelico <rosuav@gmail.com>
First post2014-01-07 13:28 +1100
Last post2014-01-07 13:28 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: the Gravity of Python 2 Chris Angelico <rosuav@gmail.com> - 2014-01-07 13:28 +1100

#63402 — Re: the Gravity of Python 2

FromChris Angelico <rosuav@gmail.com>
Date2014-01-07 13:28 +1100
SubjectRe: the Gravity of Python 2
Message-ID<mailman.5111.1389061729.18130.python-list@python.org>
On Tue, Jan 7, 2014 at 1:15 PM, Devin Jeanpierre <jeanpierreda@gmail.com> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web