Use comprehensions whenever possible
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Hugo Osvaldo Barrera · committed by Nate Prewitt · parent 2c6a842 · Browse files · 7 files·+22 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+22 added−25 removed
- tests:+2 added−2 removed
- other:+20 added−23 removed
Provenance
- Commit
89ab030- Tree
ffe8566- Author
Hugo Osvaldo Barrera <hugo@barrera.io>- Committer
Nate Prewitt <Nate.Prewitt@gmail.com>- Parent
2c6a842
7 files changed+22 added−25 removed
modified:requests/adapters.py+1 added-2 removed
127 unmodified lines128 129 self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)130 131 def __getstate__(self):132- return dict((attr, getattr(self, attr, None)) for attr in133- self.__attrs__)132+ return {attr: getattr(self, attr, None) for attr in self.__attrs__}133 134 def __setstate__(self, state):135 # Can't handle by adding 'proxy_manager' to self.__attrs__ because136 # self.poolmanager uses a lambda function, which isn't pickleable.398 unmodified linesmodified:requests/cookies.py+15 added-14 removed
442 unmodified lines443 444 By default, the pair of `name` and `value` will be set for the domain ''445 and sent on every request (this is sometimes called a "supercookie").446 """447- result = dict(448- version=0,449- name=name,450- value=value,451- port=None,452- domain='',453- path='/',454- secure=False,455- expires=None,456- discard=True,457- comment=None,458- comment_url=None,459- rest={'HttpOnly': None},460- rfc2109=False,)447+ result = {448+ 'version': 0,449+ 'name': name,450+ 'value': value,451+ 'port': None,452+ 'domain': '',453+ 'path': '/',454+ 'secure': False,455+ 'expires': None,456+ 'discard': True,457+ 'comment': None,458+ 'comment_url': None,459+ 'rest': {'HttpOnly': None},460+ 'rfc2109': False,461+ }462 463 badargs = set(kwargs) - set(result)464 if badargs:465 err = 'create_cookie() got unexpected keyword arguments: %s'84 unmodified linesmodified:requests/hooks.py+2 added-2 removed
13 unmodified lines14 HOOKS = ['response']15 16 17 def default_hooks():18- return dict((event, []) for event in HOOKS)18+ return {event: [] for event in HOOKS}19 20 # TODO: response is the only one21 22 23 def dispatch_hook(key, hooks, hook_data, **kwargs):24 """Dispatches a hook dictionary on a given piece of data."""25- hooks = hooks or dict()25+ hooks = hooks or {}26 hooks = hooks.get(key)27 if hooks:28 if hasattr(hooks, '__call__'):29 hooks = [hooks]5 unmodified linesmodified:requests/models.py+1 added-4 removed
650 unmodified lines651 # sure the content has been fully read.652 if not self._content_consumed:653 self.content654 655- return dict(656- (attr, getattr(self, attr, None))657- for attr in self.__attrs__658- )655+ return {attr: getattr(self, attr, None) for attr in self.__attrs__}656 657 def __setstate__(self, state):658 for name, value in state.items():659 setattr(self, name, value)294 unmodified linesmodified:requests/sessions.py+1 added-1 removed
736 unmodified lines737 for key in keys_to_move:738 self.adapters[key] = self.adapters.pop(key)739 740 def __getstate__(self):741- state = dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)741+ state = {attr: getattr(self, attr, None) for attr in self.__attrs__}742 return state743 744 def __setstate__(self, state):745 for attr, value in state.items():16 unmodified linesmodified:tests/test_requests.py+1 added-1 removed
862 unmodified lines863 requests.get(httpbin_secure('status', '200'))864 865 def test_urlencoded_get_query_multivalued_param(self, httpbin):866 867- r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))867+ r = requests.get(httpbin('get'), params={'test': ['foo', 'baz']})868 assert r.status_code == 200869 assert r.url == httpbin('get?test=foo&test=baz')870 871 def test_form_encoded_post_query_multivalued_element(self, httpbin):1636 unmodified linesmodified:tests/test_utils.py+1 added-1 removed
663 unmodified lines664 """665 cookiedict = {'test': 'cookies',666 'good': 'cookies'}667 cj = add_dict_to_cookiejar(cookiejar, cookiedict)668- cookies = dict((cookie.name, cookie.value) for cookie in cj)668+ cookies = {cookie.name: cookie.value for cookie in cj}669 assert cookiedict == cookies670 671 672 @pytest.mark.parametrize(110 unmodified lines