Conversation
| 'starkbank-ecdsa>=1.0.0' | ||
| ] | ||
| return deps | ||
| return ['python_http_client>=3.2.1', 'starkbank-ecdsa>=1.0.0'] |
There was a problem hiding this comment.
Function getRequires refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| mock_pers = dict() | ||
| mock_pers = { | ||
| 'to_list': [ | ||
| To("test1@example.com", "Example User"), | ||
| To("test2@example.com", "Example User"), | ||
| ] | ||
| } | ||
|
|
||
| mock_pers['to_list'] = [To("test1@example.com", | ||
| "Example User"), | ||
| To("test2@example.com", | ||
| "Example User")] |
There was a problem hiding this comment.
Function get_mock_personalization_dict refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Replace dict() with {} (
dict-literal)
| self.impersonate_subuser = impersonate_subuser | ||
| self.version = __version__ | ||
| self.useragent = 'sendgrid/{};python'.format(self.version) | ||
| self.useragent = f'sendgrid/{self.version};python' |
There was a problem hiding this comment.
Function BaseInterface.__init__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| """ | ||
| self.api_key = api_key or os.environ.get('SENDGRID_API_KEY') | ||
| auth = 'Bearer {}'.format(self.api_key) | ||
| auth = f'Bearer {self.api_key}' |
There was a problem hiding this comment.
Function SendGridAPIClient.__init__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| auth = 'Basic ' + b64encode('{}:{}'.format(self.username, self.password).encode()).decode() | ||
| auth = ( | ||
| 'Basic ' | ||
| + b64encode(f'{self.username}:{self.password}'.encode()).decode() | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function TwilioEmailAPIClient.__init__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| :type dicts: list(dict) | ||
| """ | ||
| d = dict() | ||
| d = {} |
There was a problem hiding this comment.
Function Mail._flatten_dicts refactored with the following changes:
- Replace dict() with {} (
dict-literal)
| elif isinstance(header, dict): | ||
| (k, v) = list(header.items())[0] | ||
| self._headers = self._ensure_append( | ||
| Header(k, v), self._headers) | ||
| else: | ||
| if isinstance(header, dict): | ||
| (k, v) = list(header.items())[0] | ||
| self._headers = self._ensure_append( | ||
| Header(k, v), self._headers) | ||
| else: | ||
| self._headers = self._ensure_append(header, self._headers) | ||
| self._headers = self._ensure_append(header, self._headers) |
There was a problem hiding this comment.
Function Mail.add_header refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| elif isinstance(substitution, list): | ||
| for s in substitution: | ||
| for p in self.personalizations: | ||
| p.add_substitution(substitution) | ||
| p.add_substitution(s) | ||
| else: | ||
| for p in self.personalizations: | ||
| p.add_substitution(substitution) |
There was a problem hiding this comment.
Function Mail.add_substitution refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| elif isinstance(custom_arg, dict): | ||
| (k, v) = list(custom_arg.items())[0] | ||
| self._custom_args = self._ensure_append( | ||
| CustomArg(k, v), self._custom_args) | ||
| else: | ||
| if isinstance(custom_arg, dict): | ||
| (k, v) = list(custom_arg.items())[0] | ||
| self._custom_args = self._ensure_append( | ||
| CustomArg(k, v), self._custom_args) | ||
| else: | ||
| self._custom_args = self._ensure_append( | ||
| custom_arg, self._custom_args) | ||
| self._custom_args = self._ensure_append( | ||
| custom_arg, self._custom_args) |
There was a problem hiding this comment.
Function Mail.add_custom_arg refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| if self._contents: | ||
| index = len(self._contents) | ||
| else: | ||
| index = 0 | ||
| index = len(self._contents) if self._contents else 0 |
There was a problem hiding this comment.
Function Mail.add_content refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| value = getattr(self, key) | ||
| if value: | ||
| if value := getattr(self, key): | ||
| personalization[key[:-1]] = value | ||
|
|
||
| for key in ['subject', 'send_at', 'dynamic_template_data']: | ||
| value = getattr(self, key) | ||
| if value: | ||
| if value := getattr(self, key): | ||
| personalization[key] = value | ||
|
|
||
| for prop_name in ['headers', 'substitutions', 'custom_args']: | ||
| prop = getattr(self, prop_name) | ||
| if prop: | ||
| if prop := getattr(self, prop_name): | ||
| obj = {} | ||
| for key in prop: | ||
| obj.update(key) | ||
| obj |= key |
There was a problem hiding this comment.
Function Personalization.get refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression) - Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| self._post_to_url = value | ||
| else: | ||
| self._post_to_url = SpamUrl(value) | ||
| self._post_to_url = value if isinstance(value, SpamUrl) else SpamUrl(value) |
There was a problem hiding this comment.
Function SpamCheck.post_to_url refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| # Default param | ||
| elif isinstance(request_body, dict): | ||
|
|
||
| contents = request_body.get("content", list()) | ||
|
|
||
| for content in contents: | ||
| if content is not None: | ||
| if (content.get("type") == "text/html" or | ||
| isinstance(content.get("value"), str)): | ||
| message_text = content.get("value", "") | ||
| self.validate_message_text(message_text) | ||
| if content is not None and ( | ||
| ( | ||
| content.get("type") == "text/html" | ||
| or isinstance(content.get("value"), str) | ||
| ) | ||
| ): | ||
| message_text = content.get("value", "") | ||
| self.validate_message_text(message_text) |
There was a problem hiding this comment.
Function ValidateApiKey.validate_message_dict refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
This removes the following comments ( why? ):
# Default param
| def test_init_environment_should_not_set_env_if_format_is_invalid(self): | ||
| config_file = sendgrid.helpers.inbound.config.__file__ | ||
| env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env' | ||
| env_file_path = f'{os.path.abspath(os.path.dirname(config_file))}/.env' |
There was a problem hiding this comment.
Function UnitTests.test_init_environment_should_not_set_env_if_format_is_invalid refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| name = "SomeName" | ||
| address = "test@example.com" | ||
| name_address = "{} <{}>".format(name, address) | ||
| name_address = f"{name} <{address}>" |
There was a problem hiding this comment.
Function TestEmailObject.test_add_rfc_email refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
|
|
||
| def test_useragent(self): | ||
| useragent = '{}{}{}'.format('sendgrid/', sendgrid.__version__, ';python') | ||
| useragent = f'sendgrid/{sendgrid.__version__};python' |
There was a problem hiding this comment.
Function UnitTests.test_useragent refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting)
| def get_all_ip(): | ||
| ret_val = json.loads(ret_json) | ||
| return ret_val | ||
| return json.loads(ret_json) |
There was a problem hiding this comment.
Function get_all_ip refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| data = set() | ||
| data.add("208.115.214.23") | ||
| data.add("208.115.214.22") | ||
| return data | ||
| return {"208.115.214.23", "208.115.214.22"} |
There was a problem hiding this comment.
Function make_data refactored with the following changes:
- Merge add into set declaration [×2] (
merge-set-add) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.13%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!