[issue29285] Unicode errors occur inside of multi-line comments
Eryk Sun
report at bugs.python.org
Tue Jan 17 10:29:28 EST 2017
Eryk Sun added the comment:
> they do not appear in the byte code files
It's simple to coonfirm that unassigned string literals get thrown away.:
>>> code = compile('"doc"\n"unused"\n"us"+"ed"', '', 'exec')
>>> code.co_consts
('doc', 'us', 'ed', None, 'used')
>>> dis.dis(code)
1 0 LOAD_CONST 0 ('doc')
3 STORE_NAME 0 (__doc__)
3 6 LOAD_CONST 4 ('used')
9 POP_TOP
10 LOAD_CONST 3 (None)
13 RETURN_VALUE
However, they're retained up to the abstract syntax tree:
>>> print(ast.dump(ast.parse('"doc"\n"unused"\n"us"+"ed"', '', 'exec')))
Module(body=[
Expr(value=Str(s='doc')),
Expr(value=Str(s='unused')),
Expr(value=BinOp(left=Str(s='us'),
op=Add(),
right=Str(s='ed')))])
Sans the doc string behavior, this applies to literals in general. Thus even though the compiler discards these objects, the literal still has to be parsed like any other.
----------
nosy: +eryksun
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29285>
_______________________________________
More information about the Python-bugs-list
mailing list