Skip to content

Commit

Permalink
Use comprehensions whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Osvaldo Barrera authored and nateprewitt committed Oct 17, 2018
1 parent 2c6a842 commit 89ab030
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
3 changes: 1 addition & 2 deletions requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def __init__(self, pool_connections=DEFAULT_POOLSIZE,
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)

def __getstate__(self):
return dict((attr, getattr(self, attr, None)) for attr in
self.__attrs__)
return {attr: getattr(self, attr, None) for attr in self.__attrs__}

def __setstate__(self, state):
# Can't handle by adding 'proxy_manager' to self.__attrs__ because
Expand Down
29 changes: 15 additions & 14 deletions requests/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,20 +444,21 @@ def create_cookie(name, value, **kwargs):
By default, the pair of `name` and `value` will be set for the domain ''
and sent on every request (this is sometimes called a "supercookie").
"""
result = dict(
version=0,
name=name,
value=value,
port=None,
domain='',
path='/',
secure=False,
expires=None,
discard=True,
comment=None,
comment_url=None,
rest={'HttpOnly': None},
rfc2109=False,)
result = {
'version': 0,
'name': name,
'value': value,
'port': None,
'domain': '',
'path': '/',
'secure': False,
'expires': None,
'discard': True,
'comment': None,
'comment_url': None,
'rest': {'HttpOnly': None},
'rfc2109': False,
}

badargs = set(kwargs) - set(result)
if badargs:
Expand Down
4 changes: 2 additions & 2 deletions requests/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@


def default_hooks():
return dict((event, []) for event in HOOKS)
return {event: [] for event in HOOKS}

# TODO: response is the only one


def dispatch_hook(key, hooks, hook_data, **kwargs):
"""Dispatches a hook dictionary on a given piece of data."""
hooks = hooks or dict()
hooks = hooks or {}
hooks = hooks.get(key)
if hooks:
if hasattr(hooks, '__call__'):
Expand Down
5 changes: 1 addition & 4 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,7 @@ def __getstate__(self):
if not self._content_consumed:
self.content

return dict(
(attr, getattr(self, attr, None))
for attr in self.__attrs__
)
return {attr: getattr(self, attr, None) for attr in self.__attrs__}

def __setstate__(self, state):
for name, value in state.items():
Expand Down
2 changes: 1 addition & 1 deletion requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def mount(self, prefix, adapter):
self.adapters[key] = self.adapters.pop(key)

def __getstate__(self):
state = dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)
state = {attr: getattr(self, attr, None) for attr in self.__attrs__}
return state

def __setstate__(self, state):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def test_certificate_failure(self, httpbin_secure):

def test_urlencoded_get_query_multivalued_param(self, httpbin):

r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))
r = requests.get(httpbin('get'), params={'test': ['foo', 'baz']})
assert r.status_code == 200
assert r.url == httpbin('get?test=foo&test=baz')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def test_add_dict_to_cookiejar(cookiejar):
cookiedict = {'test': 'cookies',
'good': 'cookies'}
cj = add_dict_to_cookiejar(cookiejar, cookiedict)
cookies = dict((cookie.name, cookie.value) for cookie in cj)
cookies = {cookie.name: cookie.value for cookie in cj}
assert cookiedict == cookies


Expand Down

0 comments on commit 89ab030

Please sign in to comment.