Skip to content

Commit

Permalink
style: update pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Agrendalath committed Apr 17, 2024
1 parent 652ae0a commit e99ccaf
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 74 deletions.
1 change: 1 addition & 0 deletions drag_and_drop_v2/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ def get_grading_ignore_decoys_waffle_flag():
# Ref: https://github.com/openedx/public-engineering/issues/28
return CourseWaffleFlag(WAFFLE_NAMESPACE, GRADING_IGNORE_DECOYS, __name__)
except ValueError:
# pylint: disable=toggle-missing-annotation
return CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.{GRADING_IGNORE_DECOYS}', __name__)
24 changes: 11 additions & 13 deletions drag_and_drop_v2/drag_and_drop_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import json
import logging

import six.moves.urllib.error # pylint: disable=import-error
import six.moves.urllib.parse # pylint: disable=import-error
import six.moves.urllib.request # pylint: disable=import-error
import six.moves.urllib.error
import six.moves.urllib.parse
import six.moves.urllib.request
import six
import webob

Expand Down Expand Up @@ -45,7 +45,6 @@
# Classes ###########################################################


# pylint: disable=bad-continuation
@XBlock.wants('settings')
@XBlock.wants('replace_urls')
@XBlock.wants('user') # Using `needs` breaks the Course Outline page in Maple.
Expand Down Expand Up @@ -257,7 +256,7 @@ def score(self):
"""
return Score(self.raw_earned, self.raw_possible)

def max_score(self): # pylint: disable=no-self-use
def max_score(self):
"""
Return the problem's max score, which for DnDv2 always equals 1.
Required by the grading system in the LMS.
Expand Down Expand Up @@ -515,7 +514,7 @@ def _get_block_id(self):
- In the workbench, use the usage_id.
"""
if hasattr(self, 'location'):
return self.location.html_id() # pylint: disable=no-member
return self.location.html_id()
else:
return six.text_type(self.scope_ids.usage_id)

Expand Down Expand Up @@ -581,7 +580,6 @@ def do_attempt(self, data, suffix=''):
self._validate_do_attempt()

self.attempts += 1
# pylint: disable=fixme
# TODO: Refactor this method to "freeze" item_state and pass it to methods that need access to it.
# These implicit dependencies between methods exist because most of them use `item_state` or other
# fields, either as an "input" (i.e. read value) or as output (i.e. set value) or both. As a result,
Expand Down Expand Up @@ -712,7 +710,7 @@ def has_submission_deadline_passed(self):
functionality.
"""
if hasattr(self, "has_deadline_passed"):
return self.has_deadline_passed() # pylint: disable=no-member
return self.has_deadline_passed()
else:
return False

Expand Down Expand Up @@ -949,7 +947,6 @@ def _mark_complete_and_publish_grade(self):
"""
Helper method to update `self.completed` and submit grade event if appropriate conditions met.
"""
# pylint: disable=fixme
# TODO: (arguable) split this method into "clean" functions (with no side effects and implicit state)
# This method implicitly depends on self.item_state (via is_correct and _learner_raw_score)
# and also updates self.raw_earned if some conditions are met. As a result this method implies some order of
Expand Down Expand Up @@ -1052,8 +1049,9 @@ def _expand_static_url(self, url):
# edX Studio uses a different runtime for 'studio_view' than 'student_view',
# and the 'studio_view' runtime doesn't provide the replace_urls API.
try:
from common.djangoapps.static_replace import replace_static_urls # pylint: disable=import-error
url = replace_static_urls(u'"{}"'.format(url), None, course_id=self.runtime.course_id)[1:-1]
# pylint: disable=import-outside-toplevel
from common.djangoapps.static_replace import replace_static_urls
url = replace_static_urls('"{}"'.format(url), None, course_id=self.runtime.course_id)[1:-1]
except ImportError:
pass
return url
Expand Down Expand Up @@ -1108,7 +1106,7 @@ def _get_preferred_zone(zone_count, zones):
return preferred_zone

# Set states of all items dropped in correct zones
for item_id in self.item_state:
for item_id in self.item_state: # pylint: disable=consider-using-dict-items
if self.item_state[item_id]['correct']:
state[item_id] = self.item_state[item_id]
correct_items.add(item_id)
Expand Down Expand Up @@ -1319,7 +1317,7 @@ def index_dictionary(self):
# values may be numeric / string or dict
# default implementation is an empty dict

xblock_body = super(DragAndDropBlock, self).index_dictionary()
xblock_body = super().index_dictionary()

zones_display_names = {
"zone_{}_display_name".format(zone_i):
Expand Down
19 changes: 10 additions & 9 deletions drag_and_drop_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ def sanitize_html(raw_body: str) -> str:
"""
Remove not allowed HTML tags to mitigate XSS vulnerabilities.
"""
bleach_options = dict(
tags=ALLOWED_TAGS,
protocols=bleach.ALLOWED_PROTOCOLS,
strip=True,
attributes=ALLOWED_ATTRIBUTES,
)
bleach_options['css_sanitizer'] = CSSSanitizer()
bleach_options = {
"tags": ALLOWED_TAGS,
"protocols": bleach.ALLOWED_PROTOCOLS,
"strip": True,
"attributes": ALLOWED_ATTRIBUTES,
"css_sanitizer": CSSSanitizer()
}

return bleach.clean(raw_body, **bleach_options)


Expand Down Expand Up @@ -165,8 +166,8 @@ def not_placed(number, ngettext=ngettext_fallback):
).format(missing_count=number)


FeedbackMessage = namedtuple("FeedbackMessage", ["message", "message_class"]) # pylint: disable=invalid-name
ItemStats = namedtuple( # pylint: disable=invalid-name
FeedbackMessage = namedtuple("FeedbackMessage", ["message", "message_class"])
ItemStats = namedtuple(
'ItemStats',
["required", "placed", "correctly_placed", "decoy", "decoy_in_bank"]
)
Expand Down
Loading

0 comments on commit e99ccaf

Please sign in to comment.