Skip to content

Commit 6fdd46d

Browse files
authored
Ruff: add and fix Q (except Q000) (#10094)
* Ruff: add Q001 * Ruff: fix Q001 * Ruff: add Q002 * Ruff: fix Q002 * Ruff: add Q003 * Ruff: fix Q003 * Ruff: add Q004 * Ruff: fix Q004
1 parent 39d6963 commit 6fdd46d

37 files changed

+153
-152
lines changed

dojo/api_v2/permissions.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def has_permission(self, request, view):
437437
)
438438
elif engagement_id := converted_dict.get("engagement_id"):
439439
# engagement_id doesn't exist
440-
msg = f"Engagement \"{engagement_id}\" does not exist"
440+
msg = f'Engagement "{engagement_id}" does not exist'
441441
raise serializers.ValidationError(msg)
442442

443443
if not converted_dict.get("auto_create_context"):
@@ -492,7 +492,7 @@ def has_permission(self, request, view):
492492
)
493493
elif product_id := converted_dict.get("product_id"):
494494
# product_id doesn't exist
495-
msg = f"Product \"{product_id}\" does not exist"
495+
msg = f'Product "{product_id}" does not exist'
496496
raise serializers.ValidationError(msg)
497497
else:
498498
msg = "Need product_id or product_name to perform import"
@@ -633,7 +633,7 @@ def has_permission(self, request, view):
633633
)
634634
elif test_id := converted_dict.get("test_id"):
635635
# test_id doesn't exist
636-
msg = f"Test \"{test_id}\" does not exist"
636+
msg = f'Test "{test_id}" does not exist'
637637
raise serializers.ValidationError(msg)
638638

639639
if not converted_dict.get("auto_create_context"):
@@ -927,28 +927,28 @@ def raise_no_auto_create_import_validation_error(
927927
raise ValidationError(msg)
928928

929929
if product_type_name and not product_type:
930-
msg = f"Product Type \"{product_type_name}\" does not exist"
930+
msg = f'Product Type "{product_type_name}" does not exist'
931931
raise serializers.ValidationError(msg)
932932

933933
if product_name and not product:
934934
if product_type_name:
935-
msg = f"Product \"{product_name}\" does not exist in Product_Type \"{product_type_name}\""
935+
msg = f'Product "{product_name}" does not exist in Product_Type "{product_type_name}"'
936936
raise serializers.ValidationError(msg)
937937
else:
938-
msg = f"Product \"{product_name}\" does not exist"
938+
msg = f'Product "{product_name}" does not exist'
939939
raise serializers.ValidationError(msg)
940940

941941
if engagement_name and not engagement:
942-
msg = f"Engagement \"{engagement_name}\" does not exist in Product \"{product_name}\""
942+
msg = f'Engagement "{engagement_name}" does not exist in Product "{product_name}"'
943943
raise serializers.ValidationError(msg)
944944

945945
# these are only set for reimport
946946
if test_title:
947-
msg = f"Test \"{test_title}\" with scan_type \"{scan_type}\" does not exist in Engagement \"{engagement_name}\""
947+
msg = f'Test "{test_title}" with scan_type "{scan_type}" does not exist in Engagement "{engagement_name}"'
948948
raise serializers.ValidationError(msg)
949949

950950
if scan_type:
951-
msg = f"Test with scan_type \"{scan_type}\" does not exist in Engagement \"{engagement_name}\""
951+
msg = f'Test with scan_type "{scan_type}" does not exist in Engagement "{engagement_name}"'
952952
raise serializers.ValidationError(msg)
953953

954954
raise ValidationError(error_message)
@@ -995,28 +995,28 @@ def check_auto_create_permission(
995995

996996
if product and product_name and engagement_name:
997997
if not user_has_permission(user, product, Permissions.Engagement_Add):
998-
msg = f"No permission to create engagements in product \"{product_name}\""
998+
msg = f'No permission to create engagements in product "{product_name}"'
999999
raise PermissionDenied(msg)
10001000

10011001
if not user_has_permission(
10021002
user, product, Permissions.Import_Scan_Result
10031003
):
1004-
msg = f"No permission to import scans into product \"{product_name}\""
1004+
msg = f'No permission to import scans into product "{product_name}"'
10051005
raise PermissionDenied(msg)
10061006

10071007
# all good
10081008
return True
10091009

10101010
if not product and product_name:
10111011
if not product_type_name:
1012-
msg = f"Product \"{product_name}\" does not exist and no product_type_name provided to create the new product in"
1012+
msg = f'Product "{product_name}" does not exist and no product_type_name provided to create the new product in'
10131013
raise serializers.ValidationError(msg)
10141014

10151015
if not product_type:
10161016
if not user_has_global_permission(
10171017
user, Permissions.Product_Type_Add
10181018
):
1019-
msg = f"No permission to create product_type \"{product_type_name}\""
1019+
msg = f'No permission to create product_type "{product_type_name}"'
10201020
raise PermissionDenied(msg)
10211021
# new product type can be created with current user as owner, so
10221022
# all objects in it can be created as well
@@ -1025,7 +1025,7 @@ def check_auto_create_permission(
10251025
if not user_has_permission(
10261026
user, product_type, Permissions.Product_Type_Add_Product
10271027
):
1028-
msg = f"No permission to create products in product_type \"{product_type}\""
1028+
msg = f'No permission to create products in product_type "{product_type}"'
10291029
raise PermissionDenied(msg)
10301030

10311031
# product can be created, so objects in it can be created as well

dojo/filters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ class FindingFilterHelper(FilterSet):
16151615
"The range of EPSS score percentages to filter on; the left input is a lower bound, "
16161616
"the right is an upper bound. Leaving one empty will skip that bound (e.g., leaving "
16171617
"the lower bound input empty will filter only on the upper bound -- filtering on "
1618-
"\"less than or equal\")."
1618+
'"less than or equal").'
16191619
))
16201620
epss_percentile = PercentageFilter(field_name="epss_percentile", label="EPSS percentile")
16211621
epss_percentile_range = PercentageRangeFilter(
@@ -1624,7 +1624,7 @@ class FindingFilterHelper(FilterSet):
16241624
help_text=(
16251625
"The range of EPSS percentiles to filter on; the left input is a lower bound, the right "
16261626
"is an upper bound. Leaving one empty will skip that bound (e.g., leaving the lower bound "
1627-
"input empty will filter only on the upper bound -- filtering on \"less than or equal\")."
1627+
'input empty will filter only on the upper bound -- filtering on "less than or equal").'
16281628
))
16291629

16301630
o = OrderingFilter(

dojo/finding/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ def request_finding_review(request, fid):
17091709
finding=finding,
17101710
reviewers=reviewers,
17111711
recipients=reviewers_usernames,
1712-
description=f"User {user.get_full_name()} has requested that user(s) {reviewers_string} review the finding \"{finding.title}\" for accuracy:\n\n{new_note}",
1712+
description=f'User {user.get_full_name()} has requested that user(s) {reviewers_string} review the finding "{finding.title}" for accuracy:\n\n{new_note}',
17131713
icon="check",
17141714
url=reverse("view_finding", args=(finding.id,)),
17151715
)

dojo/forms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3155,8 +3155,8 @@ def __init__(self, *args, **kwargs):
31553155
# Show in admin a multichoice list of validator names
31563156
# pass this to form using field_name='validator_name' ?
31573157
class QuestionForm(forms.Form):
3158-
''' Base class for a Question
3159-
'''
3158+
""" Base class for a Question
3159+
"""
31603160

31613161
def __init__(self, *args, **kwargs):
31623162
self.helper = FormHelper()

dojo/importers/base_importer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def sanitize_severity(
567567
# Ensure the final severity is one of the supported options
568568
if finding.severity not in SEVERITIES:
569569
msg = (
570-
f"Finding severity \"{finding.severity}\" is not supported. "
570+
f'Finding severity "{finding.severity}" is not supported. '
571571
f"Any of the following are supported: {SEVERITIES}."
572572
)
573573
raise ValidationError(msg)

dojo/importers/default_reimporter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def match_new_finding_to_existing_finding(
399399
severity=unsaved_finding.severity,
400400
numerical_severity=Finding.get_numerical_severity(unsaved_finding.severity)).order_by('id')
401401
else:
402-
logger.error(f"Internal error: unexpected deduplication_algorithm: \"{self.deduplication_algorithm}\"")
402+
logger.error(f'Internal error: unexpected deduplication_algorithm: "{self.deduplication_algorithm}"')
403403
return None
404404

405405
def process_matched_finding(

dojo/jira_link/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def post(self, request, tid=None):
544544
create_notification(
545545
event='jira_config_deleted',
546546
title=_('Deletion of JIRA: %s') % jira_instance.configuration_name,
547-
description=f"JIRA \"{jira_instance.configuration_name}\" was deleted by {request.user}",
547+
description=f'JIRA "{jira_instance.configuration_name}" was deleted by {request.user}',
548548
url=request.build_absolute_uri(reverse('jira')))
549549
return HttpResponseRedirect(reverse('jira'))
550550
except Exception as e:

dojo/management/commands/dedupe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def add_arguments(self, parser):
3838
'--parser',
3939
dest='parser',
4040
action='append',
41-
help='''List of parsers for which hash_code needs recomputing (defaults to all parsers)'''
41+
help="""List of parsers for which hash_code needs recomputing (defaults to all parsers)"""
4242
)
4343

4444
parser.add_argument('--hash_code_only', action='store_true', help='Only compute hash codes')

dojo/models.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class System_Settings(models.Model):
553553
default=True,
554554
blank=False,
555555
verbose_name=_("Password must contain one special character"),
556-
help_text=_("Requires user passwords to contain at least one special character (()[]{}|\\`~!@#$%^&*_-+=;:\'\",<>./?)."))
556+
help_text=_("Requires user passwords to contain at least one special character (()[]{}|\\`~!@#$%^&*_-+=;:'\",<>./?)."))
557557
lowercase_character_required = models.BooleanField(
558558
default=True,
559559
blank=False,
@@ -3908,7 +3908,7 @@ class JIRA_Project(models.Model):
39083908
engagement = models.OneToOneField(Engagement, on_delete=models.CASCADE, null=True, blank=True)
39093909
component = models.CharField(max_length=200, blank=True)
39103910
custom_fields = models.JSONField(max_length=200, blank=True, null=True,
3911-
help_text=_("JIRA custom field JSON mapping of Id to value, e.g. {\"customfield_10122\": [{\"name\": \"8.0.1\"}]}"))
3911+
help_text=_('JIRA custom field JSON mapping of Id to value, e.g. {"customfield_10122": [{"name": "8.0.1"}]}'))
39123912
default_assignee = models.CharField(max_length=200, blank=True, null=True,
39133913
help_text=_("JIRA default assignee (name). If left blank then it defaults to whatever is configured in JIRA."))
39143914
jira_labels = models.CharField(max_length=200, blank=True, null=True,
@@ -4384,9 +4384,9 @@ def __str__(self):
43844384
# ==============================
43854385
with warnings.catch_warnings(action="ignore", category=ManagerInheritanceWarning):
43864386
class Question(PolymorphicModel, TimeStampedModel):
4387-
'''
4387+
"""
43884388
Represents a question.
4389-
'''
4389+
"""
43904390

43914391
class Meta:
43924392
ordering = ['order']
@@ -4407,23 +4407,23 @@ def __str__(self):
44074407

44084408

44094409
class TextQuestion(Question):
4410-
'''
4410+
"""
44114411
Question with a text answer
4412-
'''
4412+
"""
44134413
objects = PolymorphicManager()
44144414

44154415
def get_form(self):
4416-
'''
4416+
"""
44174417
Returns the form for this model
4418-
'''
4418+
"""
44194419
from .forms import TextQuestionForm
44204420
return TextQuestionForm
44214421

44224422

44234423
class Choice(TimeStampedModel):
4424-
'''
4424+
"""
44254425
Model to store the choices for multi choice questions
4426-
'''
4426+
"""
44274427

44284428
order = models.PositiveIntegerField(default=1)
44294429

@@ -4437,20 +4437,20 @@ def __str__(self):
44374437

44384438

44394439
class ChoiceQuestion(Question):
4440-
'''
4440+
"""
44414441
Question with answers that are chosen from a list of choices defined
44424442
by the user.
4443-
'''
4443+
"""
44444444

44454445
multichoice = models.BooleanField(default=False,
44464446
help_text=_("Select one or more"))
44474447
choices = models.ManyToManyField(Choice)
44484448
objects = PolymorphicManager()
44494449

44504450
def get_form(self):
4451-
'''
4451+
"""
44524452
Returns the form for this model
4453-
'''
4453+
"""
44544454

44554455
from .forms import ChoiceQuestionForm
44564456
return ChoiceQuestionForm
@@ -4516,8 +4516,8 @@ def __str__(self):
45164516

45174517
with warnings.catch_warnings(action="ignore", category=ManagerInheritanceWarning):
45184518
class Answer(PolymorphicModel, TimeStampedModel):
4519-
''' Base Answer model
4520-
'''
4519+
""" Base Answer model
4520+
"""
45214521
question = models.ForeignKey(Question, on_delete=models.CASCADE)
45224522

45234523
answered_survey = models.ForeignKey(Answered_Survey,

dojo/product/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,11 @@ def view_product_metrics(request, pid):
580580
closed_findings = list(filters.get("closed", []).values('id', 'date', 'severity'))
581581
accepted_findings = list(filters.get("accepted", []).values('id', 'date', 'severity'))
582582

583-
'''
583+
"""
584584
Optimization: Create dictionaries in the structure of { finding_id: True } for index based search
585585
Previously the for-loop below used "if finding in open_findings" -- an average O(n^2) time complexity
586586
This allows for "if open_findings.get(finding_id, None)" -- an average O(n) time complexity
587-
'''
587+
"""
588588
open_findings_dict = {f.get('id'): True for f in open_findings}
589589
closed_findings_dict = {f.get('id'): True for f in closed_findings}
590590
accepted_findings_dict = {f.get('id'): True for f in accepted_findings}

dojo/search/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def simple_search(request):
364364
response.delete_cookie("highlight", path='/')
365365
return response
366366

367-
'''
367+
"""
368368
query: some keywords
369369
operators: {}
370370
keywords: ['some', 'keywords']
@@ -400,7 +400,7 @@ def simple_search(request):
400400
query: tags:anchore vulnerability_id:CVE-2020-1234 jquery
401401
operators: {'tags': ['anchore'], 'vulnerability_id': ['CVE-2020-1234']}
402402
keywords: ['jquery']
403-
'''
403+
"""
404404

405405

406406
# it's not google grade parsing, but let's do some basic stuff right

dojo/sla_config/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def edit_sla_config(request, slaid):
4242
if request.method == 'POST' and request.POST.get('delete'):
4343
if sla_config.id != 1:
4444
if Product.objects.filter(sla_configuration=sla_config).count():
45-
msg = f"The \"{sla_config}\" SLA configuration could not be deleted, as it is currently in use by one or more products."
45+
msg = f'The "{sla_config}" SLA configuration could not be deleted, as it is currently in use by one or more products.'
4646
messages.add_message(request,
4747
messages.ERROR,
4848
msg,

dojo/survey/urls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
'''
1+
"""
22
Created on Feb 18, 2015
33
44
@author: jay7958
5-
'''
5+
"""
66
from django.apps import apps
77
from django.contrib import admin
88
from django.urls import re_path

dojo/templatetags/display_tags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def notspecified(text):
378378
if text:
379379
return text
380380
else:
381-
return mark_safe("<em class=\"text-muted\">Not Specified</em>")
381+
return mark_safe('<em class="text-muted">Not Specified</em>')
382382

383383

384384
@register.tag

dojo/templatetags/survey_tags.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
'''
1+
"""
22
Created on Feb 18, 2015
33
44
@author: jay7958
5-
'''
5+
"""
66
from django import template
77

88
from dojo.models import Answered_Survey, Engagement_Survey

dojo/tools/api_sonarqube/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def get_issue(self, issue_key):
265265
if issue["key"] == issue_key:
266266
return issue
267267
msg = (
268-
f"Expected Issue \"{issue_key}\", but it returned"
268+
f'Expected Issue "{issue_key}", but it returned'
269269
f"{[x.get('key') for x in response.json().get('issues')]}. "
270270
"Full response: "
271271
f"{response.json()}"

dojo/tools/npm_audit_7_plus/parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
logger = logging.getLogger(__name__)
88

9-
'''
9+
"""
1010
the npm audit json output depends on the params used. this parser
1111
accepts the formats for any of:
1212
@@ -18,7 +18,7 @@
1818
as the report's meta block indicates, all top level keys
1919
are consiered a vulnerability and as much information as provided
2020
is added to each
21-
'''
21+
"""
2222

2323

2424
class NpmAudit7PlusParser:

dojo/user/validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def validate(self, password, user=None):
8686

8787
def get_help_text(self):
8888
return gettext('The password must contain at least 1 special character, '
89-
+ '''()[]{}|`~!@#$%^&*_-+=;:'",<>./?.''')
89+
+ """()[]{}|`~!@#$%^&*_-+=;:'",<>./?.""")
9090

9191

9292
class DojoCommonPasswordValidator(CommonPasswordValidator):

0 commit comments

Comments
 (0)