why does dead code costs time?

Bruno Dupuis python.ml.bruno.dupuis at lisael.org
Wed Dec 5 21:50:58 CET 2012


On Wed, Dec 05, 2012 at 03:41:19PM -0500, Terry Reedy wrote:
> On 12/5/2012 1:24 PM, Bruno Dupuis wrote:
> >On Wed, Dec 05, 2012 at 10:59:26AM -0700, Ian Kelly wrote:
> >>On Wed, Dec 5, 2012 at 10:34 AM, Steven D'Aprano
> >><steve+comp.lang.python at pearwood.info> wrote:
> >>>The difference is almost certain between the LOAD_CONST and the
> >>>LOAD_GLOBAL.
> >>>
> >>>As to *why* there is such a difference, I believe that's a leftover from
> >>>early Python days when None was not a keyword and could be reassigned.
> >>
> >>I think this should even be considered a bug, not just a missing
> >>optimization.  Consider:
> >
> >This is definitely a bug
> >
> >>>>>globals()['None'] = 42
> >>>>>def f(x):
> >>...     return None
> >>...     print(x)
> >>...
> >>>>>f('test')
> >>42
> >
> >This one is pretty scary
> >
> >The difference between `return None` and `return` leads to inconsistency and
> >is in contradiction with the specs, AFAIK. I'm glad we pointed this out.
> 
> You did not specify version, but I confirmed in 3.3.0. Please open a
> tracker issue.

It is also in 2.7 and 3.4 head, I didn't test other versions. I forgot
to mention here the issue I have just opened:
http://bugs.python.org/issue16619

-- 
Bruno Dupuis



More information about the Python-list mailing list