Export to GitHub

metapython - issue #2

AssertionError when running tests under Python 2.6


Posted on Jul 30, 2009 by Massive Rabbit

... 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

Comment #1

Posted on Jul 30, 2009 by Quick Panda

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

Comment #2

Posted on Oct 18, 2010 by Quick Rhino

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).

Status: Accepted

Labels:
Type-Defect Priority-Medium