Message285658
> 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. |
|
Date |
User |
Action |
Args |
2017-01-17 15:29:28 | eryksun | set | recipients:
+ eryksun, r.david.murray, zach.ware, jftuga |
2017-01-17 15:29:28 | eryksun | set | messageid: <1484666968.19.0.201362820307.issue29285@psf.upfronthosting.co.za> |
2017-01-17 15:29:28 | eryksun | link | issue29285 messages |
2017-01-17 15:29:27 | eryksun | create | |
|