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 <rep...@bugs.python.org> <http://bugs.python.org/issue29285> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com