Title: tokenize.untokenize does not maintain the order of tabbed indentations and leading spaces
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Blake Hilliard, josephgordon
Priority: normal Keywords:

Created on 2015-11-18 21:13 by Blake Hilliard, last changed 2015-12-22 08:28 by josephgordon.

Messages (1)
msg254857 - (view) Author: Blake Hilliard (Blake Hilliard) Date: 2015-11-18 21:13
Here's a simple test case that shows the bug:

# python
Python 2.7.9 (default, Apr  2 2015, 14:49:18) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import StringIO, tokenize
>>> code = "if False:\n\tx=3\n \ty=3\n"
>>> g = list(tokenize.generate_tokens(StringIO.StringIO(code).readline))
>>> assert tokenize.untokenize(g) == code
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

This is very similar to:

I'm using the patch that was provided to fix that bug, but with the patch this slightly different test case still fails. On the last line of "code" from my example, where the line begins with a single space then a tab, the untokenized string reverses the order, and the tab precedes the space. This generates code that will throw an IndentationError if run.
Date User Action Args
2015-12-22 08:28:29josephgordonsetnosy: + josephgordon
2015-11-18 21:13:27Blake Hilliardcreate