Skip to content

Commit 89ab030

Browse files
Hugo Osvaldo Barreranateprewitt
Hugo Osvaldo Barrera
authored andcommitted
Use comprehensions whenever possible
1 parent 2c6a842 commit 89ab030

File tree

7 files changed

+22
-25
lines changed

7 files changed

+22
-25
lines changed

requests/adapters.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ def __init__(self, pool_connections=DEFAULT_POOLSIZE,
129129
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
130130

131131
def __getstate__(self):
132-
return dict((attr, getattr(self, attr, None)) for attr in
133-
self.__attrs__)
132+
return {attr: getattr(self, attr, None) for attr in self.__attrs__}
134133

135134
def __setstate__(self, state):
136135
# Can't handle by adding 'proxy_manager' to self.__attrs__ because

requests/cookies.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -444,20 +444,21 @@ def create_cookie(name, value, **kwargs):
444444
By default, the pair of `name` and `value` will be set for the domain ''
445445
and sent on every request (this is sometimes called a "supercookie").
446446
"""
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+
}
461462

462463
badargs = set(kwargs) - set(result)
463464
if badargs:

requests/hooks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616

1717
def default_hooks():
18-
return dict((event, []) for event in HOOKS)
18+
return {event: [] for event in HOOKS}
1919

2020
# TODO: response is the only one
2121

2222

2323
def dispatch_hook(key, hooks, hook_data, **kwargs):
2424
"""Dispatches a hook dictionary on a given piece of data."""
25-
hooks = hooks or dict()
25+
hooks = hooks or {}
2626
hooks = hooks.get(key)
2727
if hooks:
2828
if hasattr(hooks, '__call__'):

requests/models.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,7 @@ def __getstate__(self):
652652
if not self._content_consumed:
653653
self.content
654654

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__}
659656

660657
def __setstate__(self, state):
661658
for name, value in state.items():

requests/sessions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def mount(self, prefix, adapter):
738738
self.adapters[key] = self.adapters.pop(key)
739739

740740
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__}
742742
return state
743743

744744
def __setstate__(self, state):

tests/test_requests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def test_certificate_failure(self, httpbin_secure):
864864

865865
def test_urlencoded_get_query_multivalued_param(self, httpbin):
866866

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

tests/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def test_add_dict_to_cookiejar(cookiejar):
665665
cookiedict = {'test': 'cookies',
666666
'good': 'cookies'}
667667
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}
669669
assert cookiedict == cookies
670670

671671

0 commit comments

Comments
 (0)