Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Strange __future__ behavior in Python 2.5

Reply
Thread Tools

Strange __future__ behavior in Python 2.5

 
 
mdsteele@gmail.com
Guest
Posts: n/a
 
      09-23-2006
My understanding of the __future__ statement is that you may say
something like:

from __future__ import foo, bar

to enable more than one feature. However, this does not seem to be
working properly in 2.5; it behaves as expected when typed into the
interactive interpreter, but not when it is in a module. When I try to
import the following module:

from __future__ import with_statement, division, absolute_import
def bar():
print 5/3
with open('asdf') as f:
for line in f: print line.strip()

I get a warning that 'with' will soon be a reserved keyword, and a
SyntaxError on the line with the with statement, so obviously, the
__future__ statement is not working. When I change the first line to:

from __future__ import with_statement
from __future__ import division,absolute_import

then the with statement works fine. However, the true division also
works fine, so apparently making multiple __future__ imports on one
line works for division, but not for with_statement.

Is this a bug, or am I misunderstanding something? I'm using the final
release of Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) on Mac OS X.

 
Reply With Quote
 
 
 
 
Avizoa@gmail.com
Guest
Posts: n/a
 
      09-23-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> My understanding of the __future__ statement is that you may say
> something like:
>
> from __future__ import foo, bar
>
> to enable more than one feature. However, this does not seem to be
> working properly in 2.5; it behaves as expected when typed into the
> interactive interpreter, but not when it is in a module. When I try to
> import the following module:


*snip*

> Is this a bug, or am I misunderstanding something? I'm using the final
> release of Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) on Mac OS X.



Only one "from __future__" can be imported per line.

So,
from __future__ import foo
from __future__ import bar
etc.

It will only import the first if you give multiple.

Why this is, I don't know.

 
Reply With Quote
 
 
 
 
Georg Brandl
Guest
Posts: n/a
 
      09-24-2006
(E-Mail Removed) wrote:
> My understanding of the __future__ statement is that you may say
> something like:
>
> from __future__ import foo, bar
>
> to enable more than one feature. However, this does not seem to be
> working properly in 2.5; it behaves as expected when typed into the
> interactive interpreter, but not when it is in a module. When I try to
> import the following module:
>
> from __future__ import with_statement, division, absolute_import
> def bar():
> print 5/3
> with open('asdf') as f:
> for line in f: print line.strip()
>
> I get a warning that 'with' will soon be a reserved keyword, and a
> SyntaxError on the line with the with statement, so obviously, the
> __future__ statement is not working. When I change the first line to:
>
> from __future__ import with_statement
> from __future__ import division,absolute_import
>
> then the with statement works fine. However, the true division also
> works fine, so apparently making multiple __future__ imports on one
> line works for division, but not for with_statement.
>
> Is this a bug, or am I misunderstanding something? I'm using the final
> release of Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) on Mac OS X.


This is a bug and has now been fixed in the SVN repo.
Thanks for bringing it up.

Georg
 
Reply With Quote
 
Avizoa@gmail.com
Guest
Posts: n/a
 
      09-24-2006

Georg Brandl wrote:

> This is a bug and has now been fixed in the SVN repo.
> Thanks for bringing it up.



Ouch, I feel bad now. I've been noticing this behavior since 2.5B1 but
I didn't realize it was a bug.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recommended "from __future__ import" options for Python 2.5.2? Malcolm Greene Python 1 04-12-2008 07:30 PM
from __future__ import absolute_import ? Ron Adam Python 7 02-09-2007 07:03 PM
a odd thing of "from __future__ import ..." mithrond@gmail.com Python 2 10-15-2006 01:44 AM
from __future__ import decorators Jacek Generowicz Python 8 01-17-2005 08:26 AM
'from __future__ import ...' overview Logan Python 3 11-25-2003 11:47 AM



Advertisments