[pypy-svn] r66521 - in pypy/branch/parser-compiler/pypy/interpreter/pyparser: . test

benjamin at codespeak.net benjamin at codespeak.net
Thu Jul 23 00:40:39 CEST 2009


Author: benjamin
Date: Thu Jul 23 00:40:39 2009
New Revision: 66521

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/pyparser/future.py
   pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_futureautomaton.py
Log:
fix line detection for future imports

Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/future.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/future.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/future.py	Thu Jul 23 00:40:39 2009
@@ -67,7 +67,8 @@
         self.futureFlags = futureFlags
         self.s = string
         self.pos = 0
-        self.lineno = 1
+        self.current_lineno = 1
+        self.lineno = -1
         self.line_start_pos = 0
         self.col_offset = 0
         self.docstringConsumed = False
@@ -93,7 +94,7 @@
             return
 
     def atbol(self):
-        self.lineno += 1
+        self.current_lineno += 1
         self.line_start_pos = self.pos
 
     def consumeDocstring(self):
@@ -175,6 +176,7 @@
 
     def consumeFrom(self):
         col_offset = self.pos - self.line_start_pos
+        line = self.current_lineno
         self.pos += 1
         if self.getc() == 'r' and self.getc(+1) == 'o' and self.getc(+2) == 'm':
             self.docstringConsumed = True
@@ -198,6 +200,7 @@
                 self.setFlag(self.getName())
                 self.getMore()
             self.col_offset = col_offset
+            self.lineno = line
             self.consumeEmptyLine()
         else:
             return

Modified: pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_futureautomaton.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_futureautomaton.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/pyparser/test/test_futureautomaton.py	Thu Jul 23 00:40:39 2009
@@ -124,15 +124,17 @@
 
 def test_full_chain():
     s = '"abc" #def\n  #ghi\nfrom  __future__ import (division as b, generators,);  from __future__ import with_statement\n'
-    flags = future.getFutures(future.futureFlags_2_5, s)
+    flags, pos = future.getFutures(future.futureFlags_2_5, s)
     assert flags == (fut.CO_FUTURE_DIVISION |
                      fut.CO_GENERATOR_ALLOWED |
                      fut.CO_FUTURE_WITH_STATEMENT)
+    assert pos == (3, 55)
 
 def test_intervening_code():
     s = 'from  __future__ import (division as b, generators,)\nfrom sys import modules\nfrom __future__ import with_statement\n'
-    flags = future.getFutures(future.futureFlags_2_5, s)
+    flags, pos = future.getFutures(future.futureFlags_2_5, s)
     assert flags & fut.CO_FUTURE_WITH_STATEMENT == 0
+    assert pos == (1, 0)
 
 
 def test_nonexisting():



More information about the Pypy-commit mailing list