Strange __future__ behavior in Python 2.5

Discussion in 'Python' started by mdsteele@gmail.com, Sep 23, 2006.

  1. Guest

    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.
    , Sep 23, 2006
    #1
    1. Advertising

  2. Guest

    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.
    , Sep 23, 2006
    #2
    1. Advertising

  3. Georg Brandl Guest

    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
    Georg Brandl, Sep 24, 2006
    #3
  4. Guest

    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.
    , Sep 24, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Logan
    Replies:
    3
    Views:
    756
    Michael Hudson
    Nov 25, 2003
  2. Jacek Generowicz

    from __future__ import decorators

    Jacek Generowicz, Jan 13, 2005, in forum: Python
    Replies:
    8
    Views:
    364
    Jacek Generowicz
    Jan 17, 2005
  3. Replies:
    2
    Views:
    301
  4. Ron Adam
    Replies:
    7
    Views:
    494
    Ron Adam
    Feb 9, 2007
  5. Malcolm Greene
    Replies:
    1
    Views:
    359
    Dan Bishop
    Apr 12, 2008
Loading...

Share This Page