emiamar / metapython

Automatically exported from code.google.com/p/metapython
0 stars 0 forks source link

AssertionError when running tests under Python 2.6 #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
...
  File "/home/rick446/projects/MetaPython/metapython/parse.py", line 121,
in string_from_tokens
    return tokenize.untokenize(toks)
  File "/usr/lib/python2.6/tokenize.py", line 262, in untokenize
    return ut.untokenize(iterable)
  File "/usr/lib/python2.6/tokenize.py", line 198, in untokenize
    self.add_whitespace(start)
  File "/usr/lib/python2.6/tokenize.py", line 187, in add_whitespace
    assert row <= self.prev_row
AssertionError

Original issue reported on code.google.com by rick446...@gmail.com on 30 Jul 2009 at 1:24

GoogleCodeExporter commented 8 years ago
seems the problem is somewhere esle, not in your code:

meta.py:
--------------------------------------------------------------------------
import __builtin__, imp, sys, tokenize, StringIO, tempfile

def replace_meta( fp ):
    output = [ ]
    for tkn in tokenize.generate_tokens( fp.readline ):
        output.append( tkn )
        print tkn

    modded_code = tokenize.untokenize( output )

    tfile = open( 'aaa.py', 'w' )
    tfile.write( modded_code )
    return tfile
    return StringIO.StringIO( modded_code )

def __import__(name, globals=None, locals=None, fromlist=None):
    # Fast path: see if the module has already been imported.
    print 'importing module:', name
    try:
        return sys.modules[name]
    except KeyError:
        pass

    # If any of the following calls raises an exception,
    # there's a problem we can't handle -- let the caller handle it.

    fp, pathname, description = imp.find_module(name)

    fp = replace_meta( fp )

    try:
        return imp.load_module(name, fp, pathname, description)
    finally:
        # Since we may exit via an exception, close fp explicitly.
        if fp:
            fp.close()

__builtin__.__import__ = __import__

import metapython_test

metapython_test
--------------------------------------------------------------------------

metapython_test.py:
--------------------------------------------------------------------------
def aaa():
    print 123
--------------------------------------------------------------------------

gives the same error

Matus

Original comment by mat...@gmail.com on 30 Jul 2009 at 2:05

GoogleCodeExporter commented 8 years ago
This is the bug: 

http://bugs.python.org/issue9974?@ok_message=msg%20119084%20created%3Cbr%3Eissue
%209974%20message_count,%20messages%20edited%20ok&@template=item

Doesn't happen in 2.5 (for me, anyway).

Original comment by ngv...@gmail.com on 18 Oct 2010 at 9:34