[Python-Dev] What to do for bytes in 2.6?

Guido van Rossum guido at python.org
Fri Jan 18 16:00:57 CET 2008


On Jan 18, 2008 12:27 AM, Christian Heimes <lists at cheimes.de> wrote:
> Guido van Rossum wrote:
> > Oh, you won't. Just don't use the -3 command-line flag and don't put
> > "from __future__ import <whatever>" at the top of your modules, and
> > you won't have to change your ways at all. You can continue to
> > distribute your packages in 2.5 syntax that will also work with 2.6,
> > and your users will be happy (as long as they don't want to use your
> > code on 3.0 -- but if you want to give them that, *that* is when you
> > will finally be forced to face the issue. :-)
>
> from __future__ import bytes ? What should the __future__ statement change?
>
> * "" returns unicode instead of str
> * b"" is allowed and returns bytes (a new subclass of str)
> * u"" is still allowed and returns unicode, too.
> * The str built-in is not available.

I don't think any of that is necessary. I would rather have the
following two in the language by default (see my response to Terry and
Raymond):

bytes is an alias for str (not even a subclass)
b"" is an alias for ""

> > Note that I believe that the -3 flag should not change semantics -- it
> > should only add warnings. Semantic changes must either be backwards
> > compatible or be requested explicitly with a __forward__ import (which
> > 2to3 can remove).
>
> Agreed! Should the -3 flag also warn about deprecated features which can
> easily migrated with 2to3? In the past a warning for `` (back ticks)
> were added. The feature is deprecated but the migration is very simple.

Personally, I think such warnings are misguided. -3 should augment
2to3, not duplicate its work.

> A 2to26 fixer may be worth implementing, too. It could migrate minor
> changes like `` -> repr and "except egg, spam" -> "except egg as spam".

2to3 with selected options can do that already. But again, I don't see
the point -- 2.6 code can just use 2.5 syntax and 2to3 will take care
of the migration.

There is only one thing I'd like -3 to warn about regarding except
clauses: if the 'err' variable is used past the end of the except
clause. That is a true semantic change that 2to3 cannot easily fix or
flag. Consider this an example of how 2to3 and -3 should augment each
other.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list