[issue9690] Cannot distinguish b"str" from "str" in ast module.

Kay Hayen report at bugs.python.org
Thu Aug 26 02:47:54 CEST 2010


New submission from Kay Hayen <kayhayen at gmx.de>:

There is no way to decide if a string literal should be non-unicode when the default has been set to unicode_literals. Please see: 

>>> import ast
>>> ast.dump( ast.parse( """c = "d" """ ) )
"Module(body=[Assign(targets=[Name(id='c', ctx=Store())], value=Str(s='d'))])"
>>> from __future__ import unicode_literals
>>> ast.dump( ast.parse( """c = "d" """ ) )
"Module(body=[Assign(targets=[Name(id='c', ctx=Store())], value=Str(s='d'))])"
>>> ast.dump( ast.parse( """c = b"d" """ ) )
"Module(body=[Assign(targets=[Name(id='c', ctx=Store())], value=Str(s='d'))])"
>>> ast.dump( ast.parse( """c = u"d" """ ) )
"Module(body=[Assign(targets=[Name(id='c', ctx=Store())], value=Str(s=u'd'))])"

I have checked fields, but didn't find anything either. Without an indication of the Str literal type, its type cannot be detected. In either case it is "str" and may or not have to be converted to a unicode value.

----------
components: Library (Lib)
messages: 114950
nosy: kayhayen
priority: normal
severity: normal
status: open
title: Cannot distinguish b"str" from "str" in ast module.
type: behavior
versions: Python 2.6, Python 2.7

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


More information about the Python-bugs-list mailing list