Skip to content

Commit 4de10f8

Browse files
kiblikmtesauro
andauthored
Ruff: Add and fix B006 (#11951)
Co-authored-by: Matt Tesauro <mtesauro@gmail.com>
1 parent 2fc4136 commit 4de10f8

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

dojo/importers/base_importer.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,21 @@ def update_test_tags(self):
329329

330330
def update_import_history(
331331
self,
332-
new_findings: list[Finding] = [],
333-
closed_findings: list[Finding] = [],
334-
reactivated_findings: list[Finding] = [],
335-
untouched_findings: list[Finding] = [],
332+
new_findings: list[Finding] | None = None,
333+
closed_findings: list[Finding] | None = None,
334+
reactivated_findings: list[Finding] | None = None,
335+
untouched_findings: list[Finding] | None = None,
336336
) -> Test_Import:
337337
"""Creates a record of the import or reimport operation that has occurred."""
338338
# Quick fail check to determine if we even wanted this
339+
if untouched_findings is None:
340+
untouched_findings = []
341+
if reactivated_findings is None:
342+
reactivated_findings = []
343+
if closed_findings is None:
344+
closed_findings = []
345+
if new_findings is None:
346+
new_findings = []
339347
if settings.TRACK_IMPORT_HISTORY is False:
340348
return None
341349
# Log the current state of what has occurred in case there could be
@@ -763,11 +771,19 @@ def notify_scan_added(
763771
self,
764772
test,
765773
updated_count,
766-
new_findings=[],
767-
findings_mitigated=[],
768-
findings_reactivated=[],
769-
findings_untouched=[],
774+
new_findings=None,
775+
findings_mitigated=None,
776+
findings_reactivated=None,
777+
findings_untouched=None,
770778
):
779+
if findings_untouched is None:
780+
findings_untouched = []
781+
if findings_reactivated is None:
782+
findings_reactivated = []
783+
if findings_mitigated is None:
784+
findings_mitigated = []
785+
if new_findings is None:
786+
new_findings = []
771787
logger.debug("Scan added notifications")
772788

773789
new_findings = sorted(new_findings, key=lambda x: x.numerical_severity)

dojo/importers/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def set_dict_fields(
182182
def validate(
183183
self,
184184
field_name: str,
185-
expected_types: list[Callable] = [],
185+
expected_types: list[Callable] | None = None,
186186
*,
187187
required: bool = False,
188188
default: Any = None,
@@ -193,6 +193,8 @@ def validate(
193193
and ensures it is the correct type before returning it
194194
"""
195195
# Get the value from the kwargs
196+
if expected_types is None:
197+
expected_types = []
196198
value = kwargs.get(field_name)
197199
# Make sure we have something if we need it
198200
if required is True:

dojo/jira_link/helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,10 @@ def prepare_jira_issue_fields(
742742
epic_name_field=None,
743743
default_assignee=None,
744744
duedate=None,
745-
issuetype_fields=[]):
745+
issuetype_fields=None):
746746

747+
if issuetype_fields is None:
748+
issuetype_fields = []
747749
fields = {
748750
"project": {"key": project_key},
749751
"issuetype": {"name": issuetype_name},

dojo/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ def _get_statistics_for_queryset(qs, annotation_factory):
101101
return stats
102102

103103

104-
def _manage_inherited_tags(obj, incoming_inherited_tags, potentially_existing_tags=[]):
104+
def _manage_inherited_tags(obj, incoming_inherited_tags, potentially_existing_tags=None):
105105
# get copies of the current tag lists
106+
if potentially_existing_tags is None:
107+
potentially_existing_tags = []
106108
current_inherited_tags = [] if isinstance(obj.inherited_tags, FakeTagRelatedManager) else [tag.name for tag in obj.inherited_tags.all()]
107109
tag_list = potentially_existing_tags if isinstance(obj.tags, FakeTagRelatedManager) or len(potentially_existing_tags) > 0 else [tag.name for tag in obj.tags.all()]
108110
# Clean existing tag list from the old inherited tags. This represents the tags on the object and not the product
@@ -123,7 +125,9 @@ def _manage_inherited_tags(obj, incoming_inherited_tags, potentially_existing_ta
123125
obj.tags.set(cleaned_tag_list)
124126

125127

126-
def _copy_model_util(model_in_database, exclude_fields: list[str] = []):
128+
def _copy_model_util(model_in_database, exclude_fields: list[str] | None = None):
129+
if exclude_fields is None:
130+
exclude_fields = []
127131
new_model_instance = model_in_database.__class__()
128132
for field in model_in_database._meta.fields:
129133
if field.name not in {"id", *exclude_fields}:

dojo/tags_signals.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def inherit_tags_on_instance(sender, instance, created, **kwargs):
4646
instance.inherit_tags(tag_list)
4747

4848

49-
def propagate_inheritance(instance, tag_list=[]):
49+
def propagate_inheritance(instance, tag_list=None):
5050
# Get the expected product tags
51+
if tag_list is None:
52+
tag_list = []
5153
product_inherited_tags = [tag.name for tag in get_product(instance).tags.all()]
5254
existing_inherited_tags = [tag.name for tag in instance.inherited_tags.all()]
5355
# Check if product tags already matches inherited tags

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ select = [
8585
"FURB",
8686
"DOC202", "DOC403", "DOC502",
8787
"RUF",
88+
"B006",
8889
"B009",
8990
"B010",
9091
"B033",

unittests/dojo_test_case.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def create_sla_configuration(self, name, *args, description="dummy description",
9797
sla_configuration.save()
9898
return sla_configuration
9999

100-
def create_product(self, name, *args, description="dummy description", prod_type=None, tags=[], **kwargs):
100+
def create_product(self, name, *args, description="dummy description", prod_type=None, tags=None, **kwargs):
101+
if tags is None:
102+
tags = []
101103
if not prod_type:
102104
prod_type = Product_Type.objects.first()
103105
product = Product(name=name, description=description, prod_type=prod_type, tags=tags)

0 commit comments

Comments
 (0)