-
Notifications
You must be signed in to change notification settings - Fork 6
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
Consolidate package config to pyproject.toml (Sourcery refactored) #183
base: pyproject
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.
base_formfield_callback = None | ||
for base in bases: | ||
if hasattr(base, "Meta") and hasattr(base.Meta, "formfield_callback"): | ||
base_formfield_callback = base.Meta.formfield_callback | ||
break | ||
base_formfield_callback = next( | ||
( | ||
base.Meta.formfield_callback | ||
for base in bases | ||
if hasattr(base, "Meta") | ||
and hasattr(base.Meta, "formfield_callback") | ||
), | ||
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 ModelFormMetaclass.__new__
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
"The {} could not be saved because the data didn't validate.".format(self.instance.__class__.__name__) | ||
f"The {self.instance.__class__.__name__} could not be saved because the data didn't validate." | ||
) | ||
|
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 BaseModelForm.save
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
field_setter = getattr(self, "set_" + name, None) | ||
field_setter = getattr(self, f"set_{name}", 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 BaseModelForm.update_attribute
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
class_name = model.__name__ + "Form" | ||
class_name = f"{model.__name__}Form" |
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 modelform_factory
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
raise Http404("No %s matches the given query." % query) | ||
raise Http404(f"No {query} matches the given query.") |
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_object_or_404
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
getattr(instance, "clean_" + self.name, bool)() | ||
getattr(instance, f"clean_{self.name}", bool)() |
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 column_info.validate
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if value is None: | ||
return value | ||
return str(value).strip() | ||
return value if value is None else str(value).strip() |
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 string_column_info.to_python
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
)
if value in ("f", "F"): | ||
return False | ||
return self.coercer.to_python(value) | ||
return False if value in ("f", "F") else self.coercer.to_python(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 boolean_column_info.to_python
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
)
self.label = "{}.{}".format(self.app_label, self.object_name) | ||
self.label_lower = "{}.{}".format(self.app_label, self.model_name) | ||
self.label = f"{self.app_label}.{self.object_name}" | ||
self.label_lower = f"{self.app_label}.{self.model_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 model_info.__init__
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
reprs.extend(" " + repr(i) for i in self.primary_keys.values()) | ||
reprs.extend(" " + repr(i) for _, i in sorted(self.properties.items())) | ||
reprs.extend(" " + i for i in chain(*[repr(c).split("\n") for _, c in sorted(self.composites.items())])) | ||
reprs.extend(" " + repr(i) for _, i in sorted(self.relationships.items())) | ||
reprs.extend(f" {repr(i)}" for i in self.primary_keys.values()) | ||
reprs.extend(f" {repr(i)}" for _, i in sorted(self.properties.items())) | ||
reprs.extend( | ||
f" {i}" | ||
for i in chain( | ||
*[repr(c).split("\n") for _, c in sorted(self.composites.items())] | ||
) | ||
) | ||
|
||
reprs.extend(f" {repr(i)}" for _, i in sorted(self.relationships.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 model_info.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
)
if len(pks) < 2: | ||
return next(iter(pks), None) | ||
|
||
return tuple(pks) | ||
return next(iter(pks), None) if len(pks) < 2 else tuple(pks) |
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 model_info.primary_keys_from_dict
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
)
for i in target_pk: | ||
self.local_remote_pairs_for_identity_key.append((pairs[i], i)) | ||
self.local_remote_pairs_for_identity_key.extend( | ||
(pairs[i], i) for i in target_pk | ||
) | ||
|
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 relation_info.__init__
refactored with the following changes:
- Replace a for append loop with list extend [×2] (
for-append-to-extend
)
django_sorcery/db/meta/relations.py
Outdated
if self.uselist: | ||
return ModelMultipleChoiceField | ||
|
||
return ModelChoiceField | ||
return ModelMultipleChoiceField if self.uselist else ModelChoiceField |
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 relation_info.get_form_class
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 "<relation_info({}.{})>".format(self.parent_model.__name__, self.name) | ||
return f"<relation_info({self.parent_model.__name__}.{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 relation_info.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if not (self.data or self.files): | ||
return len(self.get_queryset()) | ||
|
||
return super().initial_form_count() | ||
return ( | ||
super().initial_form_count() | ||
if (self.data or self.files) | ||
else len(self.get_queryset()) | ||
) |
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 BaseModelFormSet.initial_form_count
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 "%s_list" % model.__name__.lower() | ||
return f"{model.__name__.lower()}_list" |
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 MultipleObjectMixin.get_context_object_name
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
self.template_name_suffix = "_" + self.action | ||
self.template_name_suffix = f"_{self.action}" |
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 GenericViewSet.get_template_names
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
view.suffix = initkwargs.get("suffix", None) | ||
view.suffix = initkwargs.get("suffix") |
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 GenericViewSet.as_view
refactored with the following changes:
- Replace dict.get(x, None) with dict.get(x) (
remove-none-from-default-get
)
return "%s_list" % model.__name__.lower() | ||
return f"{model.__name__.lower()}_list" |
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 ListModelMixin.get_list_context_object_name
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if form.is_valid(): | ||
return self.form_valid(form) | ||
|
||
return self.form_invalid(form) | ||
return self.form_valid(form) if form.is_valid() else self.form_invalid(form) |
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 ModelFormMixin.process_form
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
)
instance=instance, data=self.request.POST if self.request.POST else None | ||
instance=instance, data=self.request.POST or 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 PollsViewSet.get_choice_formset
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
)
db.add_all([Owner(first_name="first_name {}".format(i), last_name="last_name {}".format(i)) for i in range(10)]) | ||
db.add_all( | ||
[ | ||
Owner(first_name=f"first_name {i}", last_name=f"last_name {i}") | ||
for i in range(10) | ||
] | ||
) | ||
|
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 TestModelChoiceField.setUp
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
db.add_all([Owner(first_name="first_name {}".format(i), last_name="last_name {}".format(i)) for i in range(10)]) | ||
db.add_all( | ||
[ | ||
Owner(first_name=f"first_name {i}", last_name=f"last_name {i}") | ||
for i in range(10) | ||
] | ||
) | ||
|
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 TestModelMultipleChoiceField.setUp
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
' <option value="{}">{}</option>'.format(self.owner.id, self.owner), | ||
f' <option value="{self.owner.id}">{self.owner}</option>', |
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 TestModelForm.test_modelform_factory_new_render
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
' <option value="{}">{}</option>'.format(self.owner.id, self.owner), | ||
f' <option value="{self.owner.id}">{self.owner}</option>', |
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 TestModelForm.test_modelform_factory_instance_render
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
self.write_migration(M1, "{}_.py".format("000000000000")) | ||
self.write_migration(M2, "{}_.py".format("000000000001")) | ||
self.write_migration(M1, '000000000000_.py') | ||
self.write_migration(M2, '000000000001_.py') |
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 TestHeads.setUp
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Simplify unnecessary nesting, casting and constant values in f-strings [×2] (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string [×2] (
remove-redundant-fstring
)
self.delete_migration("{}_.py".format(rev)) | ||
self.delete_migration(f"{rev}_.py") |
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 TestHeads.tearDown
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
"Path: {}/000000000001_.py\n".format(MIGRATION_DIR), | ||
f"Path: {MIGRATION_DIR}/000000000001_.py\n", |
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 TestHeads.test_verbose
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
self.delete_migration("{}_.py".format(rev)) | ||
self.delete_migration("{}_zero.py".format(rev)) | ||
self.delete_migration(f"{rev}_.py") | ||
self.delete_migration(f"{rev}_zero.py") |
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 TestRevision.tearDown
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
self.assertTrue(os.path.isfile(os.path.join(MIGRATION_DIR, "{}_zero.py".format(rev)))) | ||
self.assertTrue(os.path.isfile(os.path.join(MIGRATION_DIR, f"{rev}_zero.py"))) |
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 TestRevision.test_with_name
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.10%.
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! |
00af927
to
c48f621
Compare
Pull Request #182 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
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
pyproject
branch, then run:Help us improve this pull request!