[New-bugs-announce] [issue29957] unnecessary LBYL for key contained in defaultdict, lib2to3/btm_matcher

Michael Selik report at bugs.python.org
Sat Apr 1 00:37:19 EDT 2017


New submission from Michael Selik:

Minor, but it looks like someone decided to use a defaultdict but forgot to remove the checks for whether a key exists.

Creating a defaultdict(list):
https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/lib2to3/btm_matcher.py#L100

Checking for the key, then initializing an empty list:
https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/lib2to3/btm_matcher.py#L120

Again:
https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/lib2to3/btm_matcher.py#L137

Because the ``results`` is getting returned, perhaps it'd be better to use a regular dict and dict.setdefault instead of a defaultdict.

----------
components: 2to3 (2.x to 3.x conversion tool)
messages: 290955
nosy: selik
priority: normal
severity: normal
status: open
title: unnecessary LBYL for key contained in defaultdict, lib2to3/btm_matcher

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29957>
_______________________________________


More information about the New-bugs-announce mailing list