Ticket #41 (closed defect: fixed)

Opened 3 months ago

Last modified 3 months ago

Future import of division doesn't work

Reported by: kaiw Assigned to:
Priority: moderate Keywords:
Cc:

Description

I'm not sure whether this is a general problem with future imports, or specific to division.

In reinteract:

>>> from __future__ import division
>>> print 4/5
0

in the python shell:

>>> from __future__ import division
>>> print 4/5
0.8

Change History

09/02/08 19:43:54 changed by otaylor

General problem. Here's what I found in a quick examination.

  • 'from future import division' is a *compile* time thing, not a runtime thing. The compiler scans the start of the parsed syntax tree for future declarations before beginning compilation.
  • So, we'd have to emulate that scan each time we parsed a statement chunk, and if that changed, recompile the rest of the worksheet. I think this means breaking up rewrite.rewrite_and_compile() to separate out the parse/rewrite/compile steps so we can add "is this an import statement from future" step
  • It doesn't look like the parser.ASTType.compile() method supports passing flags to compile(), so we'd have to rewrite the AST of the statement of each statement we want to compile with future flagsto look like 'from future import division, ...; <real statement>'

09/07/08 04:34:16 changed by otaylor

  • status changed from new to closed.
  • resolution set to fixed.