Merge cherry-picked commit b5d2938 from @pydanny's pull request.