-
Notifications
You must be signed in to change notification settings - Fork 56
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
Sourcery refactored main branch #110
base: main
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
account = Account.objects.get(id=account_id) | ||
return account | ||
return Account.objects.get(id=account_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 get_one
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = [] | ||
for a in accounts: | ||
result.append({ | ||
'account': a.name, 'balance': list(a.balance()) | ||
}) | ||
|
||
result = [ | ||
{'account': a.name, 'balance': list(a.balance())} for a in accounts | ||
] |
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_account_balances
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
case_insensitive_username_field = '{}__iexact'.format(self.model.USERNAME_FIELD) | ||
case_insensitive_username_field = f'{self.model.USERNAME_FIELD}__iexact' |
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 EmailAccountManager.get_by_natural_key
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _FinalForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _LiteralForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _TypeGuardForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _ExtensionsSpecialForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _RequiredForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _UnpackSpecialForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._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 _UnpackForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
def __init_subclass__(self, *args, **kwds): | ||
def __init_subclass__(cls, *args, **kwds): |
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 TypeVarTuple.__init_subclass__
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
raise AttributeError("Cannot overwrite NamedTuple attribute " + key) | ||
raise AttributeError(f"Cannot overwrite NamedTuple attribute {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 _NamedTupleMeta.__new__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if hasattr(application, "__call__"): | ||
# We only check to see if its __call__ is a coroutine function - | ||
# if it's not, it still might be a coroutine function itself. | ||
if asyncio.iscoroutinefunction(application.__call__): | ||
return False | ||
if hasattr(application, "__call__") and asyncio.iscoroutinefunction( | ||
application.__call__ | ||
): | ||
return 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 is_double_callable
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
This removes the following comments ( why? ):
# if it's not, it still might be a coroutine function itself.
# We only check to see if its __call__ is a coroutine function -
self._attr_name = "_asgiref_local_impl_{}_{}".format( | ||
id(self), | ||
"".join(random.choice(string.ascii_letters) for i in range(8)), | ||
) | ||
self._attr_name = f'_asgiref_local_impl_{id(self)}_{"".join(random.choice(string.ascii_letters) for _ in range(8))}' |
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 Local.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Replace unused for index with underscore (
for-index-underscore
)
exception = details["future"].exception() | ||
if exception: | ||
if exception := details["future"].exception(): |
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 StatelessServer.application_checker
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
models_module_name = "%s.%s" % (self.name, MODELS_MODULE_NAME) | ||
models_module_name = f"{self.name}.{MODELS_MODULE_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 AppConfig.import_models
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if isinstance(entry, AppConfig): | ||
app_config = entry | ||
else: | ||
app_config = AppConfig.create(entry) | ||
app_config = entry if isinstance(entry, AppConfig) else AppConfig.create(entry) | ||
if app_config.label in self.app_configs: | ||
raise ImproperlyConfigured( | ||
"Application labels aren't unique, " | ||
"duplicates: %s" % app_config.label | ||
f"Application labels aren't unique, duplicates: {app_config.label}" |
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 Apps.populate
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace if statement with if expression (
assign-if-exp
) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
message = "No installed app with label '%s'." % app_label | ||
message = f"No installed app with label '{app_label}'." | ||
for app_config in self.get_app_configs(): | ||
if app_config.name == app_label: | ||
message += " Did you mean '%s'?" % app_config.label | ||
message += f" Did you mean '{app_config.label}'?" |
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 Apps.get_app_config
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
# Since this method is called when models are imported, it cannot | ||
# perform imports because of the risk of import loops. It mustn't | ||
# call get_app_config(). | ||
model_name = model._meta.model_name | ||
app_models = self.all_models[app_label] | ||
model_name = model._meta.model_name | ||
if model_name in app_models: | ||
if ( | ||
model.__name__ == app_models[model_name].__name__ | ||
and model.__module__ == app_models[model_name].__module__ | ||
): | ||
warnings.warn( | ||
"Model '%s.%s' was already registered. Reloading models is not " | ||
"advised as it can lead to inconsistencies, most notably with " | ||
"related models." % (app_label, model_name), | ||
f"Model '{app_label}.{model_name}' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.", | ||
RuntimeWarning, | ||
stacklevel=2, | ||
) | ||
else: | ||
raise RuntimeError( | ||
"Conflicting '%s' models in application '%s': %s and %s." | ||
% (model_name, app_label, app_models[model_name], model) | ||
f"Conflicting '{model_name}' models in application '{app_label}': {app_models[model_name]} and {model}." |
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 Apps.register_model
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
This removes the following comments ( why? ):
# Since this method is called when models are imported, it cannot
# perform imports because of the risk of import loops. It mustn't
# call get_app_config().
raise LookupError("Model '%s.%s' not registered." % (app_label, model_name)) | ||
raise LookupError(f"Model '{app_label}.{model_name}' not registered.") |
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 Apps.get_registered_model
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.16%.
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
main
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
main
branch, then run:Help us improve this pull request!