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

Kay Hayen report at bugs.python.org
Thu Aug 26 20:08:20 CEST 2010


Kay Hayen <kayhayen at gmx.de> added the comment:

Hello Benjamin,

thank you for the response. What do you mean with there is "nothing we can do about it". Is it not possible to add another field indicating the prefix given to a literal?

BTW: I believe raw strings are also no longer recognizable. Fortunately I do not need to do that, but look here:

>>> ast.dump( ast.parse( r"""a = r'\n'""" ) )
"Module(body=[Assign(targets=[Name(id='a', ctx=Store())], value=Str(s='\\\\n'))])"

Currently the only work around to not being able to tell if there was a b"" in the source code, is to open the file and check myself. And getting the actual raw string is not feasible at all.

So why not at least have an "ast" module that allows to decide without ambiguity what the user said. I agree that raw strings can be solved before the AST and it doesn't matter much. But I don't think it's acceptable that CPython can execute the code correctly, but using the AST nodes, there is no way to tell.

I thought they share code?

Yours,
Kay

----------

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


More information about the Python-bugs-list mailing list