Skip to content

Conversation

@selik
Copy link
Contributor

@selik selik commented Apr 1, 2017

The results was constructed as a defaultdict and we could simply
delete the check if key not in results. However, I think it's safer
to use dict.setdefault as I'm not sure whether the caller expects a
regular dict or defaultdict.

The ``results`` was constructed as a defaultdict and we could simply
delete the check ``if key not in results``. However, I think it's safer
to use dict.setdefault as I'm not sure whether the caller expects a
regular dict or defaultdict.
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@benjaminp
Copy link
Contributor

Why switch to setdefault when the defaultdict would work?

@selik
Copy link
Contributor Author

selik commented Apr 1, 2017

The caller may expect that looking up a missing key will raise KeyError instead of inserting with an empty list. The defaultdict didn't bother anyone before, presumably, but this might make it just a tad friendlier.

I don't know enough about the context here for how the run function will be used, but given that the docstring says it returns a "dictionary of node matches with fixers as the keys" and doesn't mention that it's a defaultdict, returning exactly a dict may be best.

@selik
Copy link
Contributor Author

selik commented Apr 1, 2017

I switched it back to defaultdict. @rhettinger says it'll be "a little more compact, faster, and nice looking" (http://bugs.python.org/msg290993).

@benjaminp benjaminp merged commit 11fa3c7 into python:master Apr 2, 2017
@selik selik deleted the fix-issue-29957 branch October 31, 2017 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants