-
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
|
Hey! Changelogs info seems to be missing or might be in incorrect format. |
|
Authentication to CNP for DevOps failed. Click here to try again: https://portal.cwp.radwarecloud.com/github-plugin.html?installation_id=26169338&setup_action=install |
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
| any_prefix_is_slash[:] = [True] | ||
| if not param.is_flag and not param.count: | ||
| rv += " " + param.make_metavar() | ||
| rv += f" {param.make_metavar()}" |
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 get_opts._write refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| def write_page(out, data): | ||
| path = data["path"] | ||
| filename = os.path.join(out, *path[1:]) + "/index.rst" | ||
| filename = f"{os.path.join(out, *path[1:])}/index.rst" |
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 write_page refactored with the following changes:
- Simplify generator expression (
simplify-generator) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring) - Merge append into list declaration [×4] (
merge-list-append) - Replace a for append loop with list extend [×2] (
for-append-to-extend) - Merge consecutive list appends into a single extend [×6] (
merge-list-appends-into-extend)
| ", ".join("%s" % d for d in param.default) | ||
| ", ".join(f"{d}" for d in param.default) | ||
| if isinstance(param.default, (list, tuple)) | ||
| else (param.default,) | ||
| ) | ||
|
|
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 dump_command refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if not item: | ||
| return False | ||
| return True | ||
| return bool(msg.string) if isinstance(msg.string, bytes) else all(msg.string) |
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 is_translated refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Use any() instead of for loop (
use-any) - Invert any/all to simplify comparisons (
invert-any-all) - Simplify generator expression (
simplify-generator)
| filename = "raven/base.py" | ||
| else: | ||
| filename = random.choice(loremipsum.words) + ".js" | ||
| filename = f"{random.choice(loremipsum.words)}.js" |
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 generate_commits refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| def pre_save(self, instance, add): | ||
| value = getattr(instance, self.attname) | ||
| return value | ||
| return getattr(instance, self.attname) |
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 BitField.pre_save refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| self._value = int(value) | ||
| else: | ||
| self._value = 0 | ||
| self._value = int(value) if value else 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 BitHandler.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if not isinstance(other, BitHandler): | ||
| return False | ||
| return self._value == other._value | ||
| return self._value == other._value if isinstance(other, BitHandler) else False |
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 BitHandler.__eq__ refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| return "<{}: {}>".format( | ||
| self.__class__.__name__, | ||
| ", ".join(f"{k}={self.get_bit(n).is_set}" for n, k in enumerate(self._keys)), | ||
| ) | ||
| return f'<{self.__class__.__name__}: {", ".join((f"{k}={self.get_bit(n).is_set}" for n, k in enumerate(self._keys)))}>' |
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 BitHandler.__repr__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| raise AttributeError("%s is not a valid flag" % key) | ||
| raise AttributeError(f"{key} is not a valid flag") |
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 BitHandler.__getattr__ refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| raise AttributeError("%s is not a valid flag" % key) | ||
| raise AttributeError(f"{key} is not a valid flag") |
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 BitHandler.__setattr__ refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if __build__: | ||
| return f"{__version__}.{__build__}" | ||
| return __version__ | ||
| return f"{__version__}.{__build__}" if __build__ else __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 get_version refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| return '<pre style="display:inline-block;white-space:pre-wrap;">{}</pre>'.format( | ||
| escape(saferepr(instance.value)) | ||
| ) | ||
| return f'<pre style="display:inline-block;white-space:pre-wrap;">{escape(saferepr(instance.value))}</pre>' |
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 OptionAdmin.value_repr refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if not obj: | ||
| return self.add_fieldsets | ||
| return super().get_fieldsets(request, obj) | ||
| return super().get_fieldsets(request, obj) if obj else self.add_fieldsets |
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 UserAdmin.get_fieldsets refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| defaults.update( | ||
| {"form": self.add_form, "fields": admin.util.flatten_fieldsets(self.add_fieldsets)} | ||
| ) | ||
| defaults.update(kwargs) | ||
| defaults |= { | ||
| "form": self.add_form, | ||
| "fields": admin.util.flatten_fieldsets(self.add_fieldsets), | ||
| } | ||
|
|
||
| defaults |= kwargs |
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 UserAdmin.get_form refactored with the following changes:
- Merge dictionary updates via the union operator [×2] (
dict-assign-update-to-union)
| missing_attachment_types = required_attachment_types - {ea.type for ea in attachments} | ||
|
|
||
| if missing_attachment_types: | ||
| if missing_attachment_types := required_attachment_types - { | ||
| ea.type for ea in attachments | ||
| }: |
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 pull_event_data refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| new_sdk_version = self.new_sdk_version | ||
| if self.ignore_patch_version: | ||
| new_sdk_version = ".".join(v for v in new_sdk_version.split(".")[:2]) | ||
| new_sdk_version = ".".join(new_sdk_version.split(".")[:2]) |
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 UpdateSDKSuggestion.get_new_state refactored with the following changes:
- Simplify generator expression (
simplify-generator)
| if not settings.SENTRY_RELEASE_REGISTRY_BASEURL: | ||
| return {} | ||
|
|
||
| return cache.get(SDK_INDEX_CACHE_KEY) or {} | ||
| return ( | ||
| cache.get(SDK_INDEX_CACHE_KEY) or {} | ||
| if settings.SENTRY_RELEASE_REGISTRY_BASEURL | ||
| 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 get_sdk_index refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| rv.update((key, info["main_docs_url"]) for (key, info) in get_sdk_index().items()) | ||
| rv |= ((key, info["main_docs_url"]) for (key, info) in get_sdk_index().items()) |
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 get_sdk_urls refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union)
|
|
||
| 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 Analytics.setup refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass)
| new_value = {} | ||
| for attr in self.attributes: | ||
| new_value[attr.name] = attr.extract(getattr(value, attr.name, None)) | ||
| new_value = { | ||
| attr.name: attr.extract(getattr(value, attr.name, None)) | ||
| for attr in self.attributes | ||
| } | ||
|
|
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 Map.extract refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension)
|
|
||
| if items: | ||
| raise ValueError("Unknown attributes: {}".format(", ".join(items.keys()))) | ||
| raise ValueError(f'Unknown attributes: {", ".join(items.keys())}') |
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 get_data refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| base_url = f"{base_url}?{querystring}" | ||
| else: | ||
| base_url = base_url + "?" | ||
| base_url = f"{base_url}?" |
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 Endpoint.build_cursor_link refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| allowed_origins = request.auth.get_allowed_origins() | ||
| else: | ||
| allowed_origins = None | ||
| allowed_origins = request.auth.get_allowed_origins() if request.auth else 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 Endpoint.dispatch refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if end: | ||
| end = to_datetime(float(end)) | ||
| else: | ||
| end = datetime.utcnow().replace(tzinfo=utc) | ||
| end = to_datetime(float(end)) if end else datetime.utcnow().replace(tzinfo=utc) |
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 StatsMixin._parse_args refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| elif ("-%s" % self.key) in queryset.query.order_by: | ||
| elif f"-{self.key}" in queryset.query.order_by: | ||
| if asc: | ||
| index = queryset.query.order_by.index(f"-{self.key}") | ||
| new_order_by = list(queryset.query.order_by) | ||
| new_order_by[index] = queryset.query.order_by[index][1:] | ||
| queryset.query.order_b = tuple(new_order_by) | ||
| elif asc: | ||
| queryset = queryset.order_by(self.key) | ||
| else: | ||
| if asc: | ||
| queryset = queryset.order_by(self.key) | ||
| else: | ||
| queryset = queryset.order_by("-%s" % self.key) | ||
| queryset = queryset.order_by(f"-{self.key}") |
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 BasePaginator.build_queryset refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| if cursor.value: | ||
| cursor_value = self.value_from_cursor(cursor) | ||
| else: | ||
| cursor_value = 0 | ||
|
|
||
| cursor_value = self.value_from_cursor(cursor) if cursor.value else 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 BasePaginator.get_result refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| return math.floor(value) if self._is_asc(cursor.is_prev) else math.ceil(value) | ||
| if isinstance(value, str): | ||
| return unquote(value) | ||
| return 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 CombinedQuerysetPaginator.value_from_cursor refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| sort_keys = [] | ||
| sort_keys.append(self.get_item_key(item, is_prev)) | ||
| sort_keys = [self.get_item_key(item, is_prev)] |
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 CombinedQuerysetPaginator._build_combined_querysets._sort_combined_querysets refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| if cursor.value: | ||
| cursor_value = self.value_from_cursor(cursor) | ||
| else: | ||
| cursor_value = None | ||
|
|
||
| cursor_value = self.value_from_cursor(cursor) if cursor.value else 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 CombinedQuerysetPaginator.get_result refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.07%.
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
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!