Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Apr 21, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from edson-github April 21, 2022 13:02
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

return
if "(required)" not in desc:
pname = pname + "=None"
pname = f"{pname}=None"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function method_params.add_param refactored with the following changes:

if i == 0:
display = root_discovery.get("title", display)
crumbs.append('<a href="{}.html">{}</a>'.format(prefix + p, display))
crumbs.append(f'<a href="{prefix + p}.html">{display}</a>')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function breadcrumbs refactored with the following changes:

Comment on lines -317 to 320
css,
"<h1>%s</h1>" % breadcrumbs(path[:-1], root_discovery),
f"<h1>{breadcrumbs(path[:-1], root_discovery)}</h1>",
"<h2>Instance Methods</h2>",
]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function document_collection refactored with the following changes:

Comment on lines -365 to +370
f = open(os.path.join(FLAGS.dest, path + "html"), "w")
if sys.version_info.major < 3:
html = html.encode("utf-8")

f.write(html)
f.close()
with open(os.path.join(FLAGS.dest, f"{path}html"), "w") as f:
if sys.version_info.major < 3:
html = html.encode("utf-8")

f.write(html)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function document_collection_recursive refactored with the following changes:

Comment on lines -401 to +403
print("Warning: {} {} found but could not be built.".format(name, version))
print(f"Warning: {name} {version} found but could not be built.")
return
except HttpError as e:
print("Warning: {} {} returned {}.".format(name, version, e))
print(f"Warning: {name} {version} returned {e}.")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function document_api refactored with the following changes:

@@ -1,5 +1,6 @@
"""Retain apiclient as an alias for googleapiclient."""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 36-36 refactored with the following changes:

Comment on lines -85 to +93
else:
try:
if credentials.create_scoped_required():
return credentials.create_scoped(scopes)
else:
return credentials
except AttributeError:
return credentials
try:
return (
credentials.create_scoped(scopes)
if credentials.create_scoped_required()
else credentials
)

except AttributeError:
return credentials
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with_scopes refactored with the following changes:

Comment on lines -109 to +121
if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials):
if google_auth_httplib2 is None:
raise ValueError(
"Credentials from google.auth specified, but "
"google-api-python-client is unable to use these credentials "
"unless google-auth-httplib2 is installed. Please install "
"google-auth-httplib2."
)
return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http())
else:
if not HAS_GOOGLE_AUTH or not isinstance(
credentials, google.auth.credentials.Credentials
):
return credentials.authorize(build_http())
if google_auth_httplib2 is None:
raise ValueError(
"Credentials from google.auth specified, but "
"google-api-python-client is unable to use these credentials "
"unless google-auth-httplib2 is installed. Please install "
"google-auth-httplib2."
)
return google_auth_httplib2.AuthorizedHttp(credentials, http=build_http())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function authorized_http refactored with the following changes:

Comment on lines -128 to +135
if HAS_GOOGLE_AUTH and isinstance(credentials, google.auth.credentials.Credentials):
request = google_auth_httplib2.Request(refresh_http)
return credentials.refresh(request)
else:
if not HAS_GOOGLE_AUTH or not isinstance(
credentials, google.auth.credentials.Credentials
):
return credentials.refresh(refresh_http)
request = google_auth_httplib2.Request(refresh_http)
return credentials.refresh(request)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function refresh_credentials refactored with the following changes:

plural_s = ""
if max_positional_args != 1:
plural_s = "s"
plural_s = "s" if max_positional_args != 1 else ""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function positional.positional_decorator.positional_wrapper refactored with the following changes:

Comment on lines -161 to +160
msg = "URL-encoded content contains a repeated value:" "%s -> %s" % (
key,
", ".join(value),
)
msg = f'URL-encoded content contains a repeated value:{key} -> {", ".join(value)}'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_unique_urlencoded refactored with the following changes:

Comment on lines -208 to +204
if value is None:
return url
else:
return update_query_params(url, {name: value})
return url if value is None else update_query_params(url, {name: value})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _add_query_parameter refactored with the following changes:

for k, v in six.iteritems(headers):
new_headers[k.upper()] = v
return new_headers
return {k.upper(): v for k, v in six.iteritems(headers)}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _upper_header_keys refactored with the following changes:

Comment on lines -273 to +277
"Channel id mismatch: %s != %s" % (channel.id, channel_id)
f"Channel id mismatch: {channel.id} != {channel_id}"
)
else:
message_number = int(headers[X_GOOG_MESSAGE_NUMBER])
state = headers[X_GOOG_RESOURCE_STATE]
resource_uri = headers[X_GOOG_RESOURCE_URI]
resource_id = headers[X_GOOG_RESOURCE_ID]
return Notification(message_number, state, resource_uri, resource_id)

message_number = int(headers[X_GOOG_MESSAGE_NUMBER])
state = headers[X_GOOG_RESOURCE_STATE]
resource_uri = headers[X_GOOG_RESOURCE_URI]
resource_id = headers[X_GOOG_RESOURCE_ID]
return Notification(message_number, state, resource_uri, resource_id)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function notification_from_headers refactored with the following changes:

Comment on lines -307 to +304
if expiration_ms < 0:
expiration_ms = 0

expiration_ms = max(expiration_ms, 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function new_webhook_channel refactored with the following changes:

Comment on lines -58 to +65
error_detail_keyword = next((kw for kw in ["detail", "details", "message"] if kw in data["error"]), "")
if error_detail_keyword:
if error_detail_keyword := next(
(
kw
for kw in ["detail", "details", "message"]
if kw in data["error"]
),
"",
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HttpError._get_reason refactored with the following changes:

Comment on lines -174 to +180
"Received unexpected call %s" % methodId
f"Received unexpected call {methodId}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function UnexpectedMethodError.__init__ refactored with the following changes:

Comment on lines -184 to +190
"Expected: [%s] - Provided: [%s]" % (expected, provided)
f"Expected: [{expected}] - Provided: [{provided}]"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function UnexpectedBodyError.__init__ refactored with the following changes:

else:
reason = data[0]["error"]["errors"]["reason"]
except (UnicodeDecodeError, ValueError, KeyError):
except (ValueError, KeyError):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _should_retry_response refactored with the following changes:

self._fd = fd
self._mimetype = mimetype
if not (chunksize == -1 or chunksize > 0):
if chunksize != -1 and chunksize <= 0:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MediaIoBaseUpload.__init__ refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -583 to +585
if mimetype is None:
# Guess failed, use octet-stream.
mimetype = "application/octet-stream"
if mimetype is None:
# Guess failed, use octet-stream.
mimetype = "application/octet-stream"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MediaFileUpload.__init__ refactored with the following changes:

Comment on lines -692 to +696
self._headers = {}
for k, v in six.iteritems(request.headers):
# allow users to supply custom headers by setting them on the request
# but strip out the ones that are set by default on requests generated by
# API methods like Drive's files().get(fileId=...)
if not k.lower() in ("accept", "accept-encoding", "user-agent"):
self._headers[k] = v
self._headers = {
k: v
for k, v in six.iteritems(request.headers)
if k.lower() not in ("accept", "accept-encoding", "user-agent")
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MediaIoBaseDownload.__init__ refactored with the following changes:

  • Convert for loop into dictionary comprehension (dict-comprehension)
  • Simplify logical expression using De Morgan identities (de-morgan)

This removes the following comments ( why? ):

# but strip out the ones that are set by default on requests generated by
# allow users to supply custom headers by setting them on the request
# API methods like Drive's files().get(fileId=...)

Comment on lines -977 to +975
if self.resumable.size() is None:
size = "*"
else:
size = str(self.resumable.size())

size = "*" if self.resumable.size() is None else str(self.resumable.size())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HttpRequest.next_chunk refactored with the following changes:

Comment on lines -1247 to +1243
if creds is not None:
if id(creds) not in self._refreshed_credentials:
_auth.refresh_credentials(creds)
self._refreshed_credentials[id(creds)] = 1
if creds is not None and id(creds) not in self._refreshed_credentials:
_auth.refresh_credentials(creds)
self._refreshed_credentials[id(creds)] = 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BatchHttpRequest._refresh_and_apply_credentials refactored with the following changes:

Comment on lines -1274 to +1267
return "<%s + %s>" % (self._base_id, quote(id_))
return f"<{self._base_id} + {quote(id_)}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BatchHttpRequest._id_to_header refactored with the following changes:

Comment on lines -155 to +158
headers["x-goog-api-client"] += "gdcl/%s gl-python/%s" % (
_LIBRARY_VERSION,
_PY_VERSION,
)
headers[
"x-goog-api-client"
] += f"gdcl/{_LIBRARY_VERSION} gl-python/{_PY_VERSION}"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseModel.request refactored with the following changes:

value = value.encode("utf-8")
astuples.append((key, value))
return "?" + urlencode(astuples)
return f"?{urlencode(astuples)}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseModel._build_query refactored with the following changes:

Comment on lines -213 to +221
# Error handling is TBD, for example, do we retry
# for some operation/error combinations?
if resp.status < 300:
if resp.status == 204:
# A 204: No Content response should be treated differently
# to all the other success states
return self.no_content_response
return self.deserialize(content)
else:
LOGGER.debug("Content from bad request was: %r" % content)
raise HttpError(resp, content)
return (
self.no_content_response
if resp.status == 204
else self.deserialize(content)
)

LOGGER.debug("Content from bad request was: %r" % content)
raise HttpError(resp, content)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseModel.response refactored with the following changes:

This removes the following comments ( why? ):

# to all the other success states
# Error handling is TBD, for example, do we retry
# A 204: No Content response should be treated differently
# for some operation/error combinations?

Comment on lines -400 to -402
else:
# Don't add anything to patch if there's no change
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function makepatch refactored with the following changes:

This removes the following comments ( why? ):

# Don't add anything to patch if there's no change


if scope is None:
scope = "https://www.googleapis.com/auth/" + name
scope = f"https://www.googleapis.com/auth/{name}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant