[issue24447] tab indentation breaks in tokenize.untokenize

Dingyuan Wang report at bugs.python.org
Sun Jun 14 05:33:14 CEST 2015


New submission from Dingyuan Wang:

If a script uses tabs for indentation, tokenize.untokenize won't restore original indentation correctly from the second line of the indentation level, and thus breaks the file.

This affects all Python versions.

Test code:

python2 -c 'import sys, tokenize; sys.stdout.write(tokenize.untokenize(tokenize.generate_tokens(sys.stdin.readline)))' < tab.py

python3 -c 'import sys, tokenize; sys.stdout.buffer.write(tokenize.untokenize(tokenize.tokenize(sys.stdin.buffer.readline)))' < tab.py

Out:

def foo():
	pass
 pass
 if 1:
		pass
  pass

----------
components: Library (Lib)
files: tab.py
messages: 245333
nosy: gumblex
priority: normal
severity: normal
status: open
title: tab indentation breaks in tokenize.untokenize
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file39704/tab.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24447>
_______________________________________


More information about the Python-bugs-list mailing list