Skip to content

Commit d5cf4e0

Browse files
authored
fix: remove repeated calls to self._get_reason (googleapis#1513)
self._get_reason is being called in \_\_init\_\_ (googleapis#1185) , so why not save it then? also in the \_\_repr\_\_ function we got the reason by calling the _get_reason function right in the beginning, but was then called again.
1 parent bbc4385 commit d5cf4e0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

googleapiclient/errors.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, resp, content, uri=None):
4343
self.content = content
4444
self.uri = uri
4545
self.error_details = ""
46-
self._get_reason()
46+
self.reason = self._get_reason()
4747

4848
@property
4949
def status_code(self):
@@ -75,25 +75,24 @@ def _get_reason(self):
7575
pass
7676
if reason is None:
7777
reason = ""
78-
return reason
78+
return reason.strip()
7979

8080
def __repr__(self):
81-
reason = self._get_reason()
8281
if self.error_details:
8382
return '<HttpError %s when requesting %s returned "%s". Details: "%s">' % (
8483
self.resp.status,
8584
self.uri,
86-
reason.strip(),
85+
self.reason,
8786
self.error_details,
8887
)
8988
elif self.uri:
9089
return '<HttpError %s when requesting %s returned "%s">' % (
9190
self.resp.status,
9291
self.uri,
93-
self._get_reason().strip(),
92+
self.reason,
9493
)
9594
else:
96-
return '<HttpError %s "%s">' % (self.resp.status, self._get_reason())
95+
return '<HttpError %s "%s">' % (self.resp.status, self.reason)
9796

9897
__str__ = __repr__
9998

0 commit comments

Comments
 (0)