-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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" |
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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>') |
There was a problem hiding this comment.
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:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| css, | ||
| "<h1>%s</h1>" % breadcrumbs(path[:-1], root_discovery), | ||
| f"<h1>{breadcrumbs(path[:-1], root_discovery)}</h1>", | ||
| "<h2>Instance Methods</h2>", | ||
| ] | ||
|
|
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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) |
There was a problem hiding this comment.
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:
- Use
withwhen opening file to ensure closure (ensure-file-closed) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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}.") |
There was a problem hiding this comment.
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:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| @@ -1,5 +1,6 @@ | |||
| """Retain apiclient as an alias for googleapiclient.""" | |||
|
|
|||
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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 |
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition (
remove-unnecessary-else) - Replace if statement with if expression (
assign-if-exp)
| 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()) |
There was a problem hiding this comment.
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:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| 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) |
There was a problem hiding this comment.
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:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| plural_s = "" | ||
| if max_positional_args != 1: | ||
| plural_s = "s" | ||
| plural_s = "s" if max_positional_args != 1 else "" |
There was a problem hiding this comment.
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:
- Replace if statement with if expression (
assign-if-exp) - Move setting of default value for variable into
elsebranch (introduce-default-else)
| 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)}' | ||
|
|
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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}) |
There was a problem hiding this comment.
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:
- Replace if statement with if expression (
assign-if-exp)
| 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)} |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Convert for loop into dictionary comprehension (
dict-comprehension)
| "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) |
There was a problem hiding this comment.
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:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if expiration_ms < 0: | ||
| expiration_ms = 0 | ||
|
|
||
| expiration_ms = max(expiration_ms, 0) |
There was a problem hiding this comment.
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:
- Replace comparison with min/max call (
min-max-identity)
| 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"] | ||
| ), | ||
| "", | ||
| ): |
There was a problem hiding this comment.
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:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| "Received unexpected call %s" % methodId | ||
| f"Received unexpected call {methodId}" |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| "Expected: [%s] - Provided: [%s]" % (expected, provided) | ||
| f"Expected: [{expected}] - Provided: [{provided}]" |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| else: | ||
| reason = data[0]["error"]["errors"]["reason"] | ||
| except (UnicodeDecodeError, ValueError, KeyError): | ||
| except (ValueError, KeyError): |
There was a problem hiding this comment.
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:
- Remove redundant exceptions from an except clause (
remove-redundant-exception)
| self._fd = fd | ||
| self._mimetype = mimetype | ||
| if not (chunksize == -1 or chunksize > 0): | ||
| if chunksize != -1 and chunksize <= 0: |
There was a problem hiding this comment.
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)
| 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" |
There was a problem hiding this comment.
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:
- Hoist conditional out of nested conditional (
hoist-if-from-if)
| 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") | ||
| } |
There was a problem hiding this comment.
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=...)
| 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()) |
There was a problem hiding this comment.
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:
- Replace if statement with if expression (
assign-if-exp) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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 |
There was a problem hiding this comment.
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:
- Merge nested if conditions (
merge-nested-ifs)
| return "<%s + %s>" % (self._base_id, quote(id_)) | ||
| return f"<{self._base_id} + {quote(id_)}>" |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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}" | ||
|
|
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| value = value.encode("utf-8") | ||
| astuples.append((key, value)) | ||
| return "?" + urlencode(astuples) | ||
| return f"?{urlencode(astuples)}" |
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| # 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) |
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition (
remove-unnecessary-else) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
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?
| else: | ||
| # Don't add anything to patch if there's no change | ||
| pass |
There was a problem hiding this comment.
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:
- Remove redundant pass statement (
remove-redundant-pass)
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}" |
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!