[issue27937] logging.getLevelName microoptimization

2016-09-03 Thread Roundup Robot
Roundup Robot added the comment: New changeset 0986401d0733 by Vinay Sajip in branch 'default': Fixes #27937: optimise code used in all logging calls. https://hg.python.org/cpython/rev/0986401d0733 New changeset e4b6faf22e8d by Vinay Sajip in branch '3.5': Fixes #27937: optimise code used in all

[issue27937] logging.getLevelName microoptimization

2016-09-02 Thread R. David Murray
R. David Murray added the comment: Parens do not cause lazy evaluation unless what is parenthesized is a generator comprehension. An expanded if solution is the correct one. If Vinay prefers a one liner, I think you could also write: _levelToName.get(level) or _nameToLevel.get(level) or

[issue27937] logging.getLevelName microoptimization

2016-09-02 Thread Ondřej Medek
Ondřej Medek added the comment: That's probably my lack of Python knowledge. I have though that parentheses in ("Level %s" % level) cause lazy evaluation. If not, then this code has to be optimized by if-then, too. -- ___ Python tracker

[issue27937] logging.getLevelName microoptimization

2016-09-02 Thread Xiang Zhang
Xiang Zhang added the comment: No, I mean this method you propose: return _levelToName.get(level, (_nameToLevel.get(level, ("Level %s" % level I cannot see any difference with the original code, except parentheses. -- ___ Python tracker

[issue27937] logging.getLevelName microoptimization

2016-09-02 Thread Ondřej Medek
Ondřej Medek added the comment: Which 'first' method do you mean? logging.getLevelName() converts level (int) to level name (str). But due to the backward compatibility is also converts level name (str) to level (int). -- ___ Python tracker

[issue27937] logging.getLevelName microoptimization

2016-09-02 Thread Xiang Zhang
Xiang Zhang added the comment: What's the meaning of the first method? -- nosy: +xiang.zhang ___ Python tracker ___ ___ Python-bugs-li

[issue27937] logging.getLevelName microoptimization

2016-09-02 Thread Ondřej Medek
New submission from Ondřej Medek: The logging.getLevelName contains code: return _levelToName.get(level, _nameToLevel.get(level, ("Level %s" % level))) I am still a Python beginner, but I think the most of the times the _nameToLevel.get is called unnecessarily. IMHO the code should be return