Skip to content

Commit

Permalink
refactor: drop unnecessary type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Feb 4, 2025
1 parent 8996b91 commit 93e0105
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 49 deletions.
2 changes: 1 addition & 1 deletion openedx_filters/course_authoring/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LMSPageURLRequested(OpenEdxPublicFilter):
- Function or Method: get_asset_json
"""

filter_type: str = "org.openedx.course_authoring.lms.page.url.requested.v1"
filter_type = "org.openedx.course_authoring.lms.page.url.requested.v1"

@classmethod
def run_filter(cls, url: str, org: str) -> tuple[str, str]:
Expand Down
4 changes: 2 additions & 2 deletions openedx_filters/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class OpenEdxFilterException(Exception):

def __init__(
self,
message: Optional[str] = "",
redirect_to: Optional[str] = "",
message: str = "",
redirect_to: str = "",
status_code: Optional[int] = None,
**kwargs
) -> None:
Expand Down
50 changes: 25 additions & 25 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AccountSettingsRenderStarted(OpenEdxPublicFilter):
This filter doesn't work alongside the account MFE, only with the legacy account settings page.
"""

filter_type: str = "org.openedx.learning.student.settings.render.started.v1"
filter_type = "org.openedx.learning.student.settings.render.started.v1"

class RedirectToPage(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -107,7 +107,7 @@ def run_filter(cls, context: dict, template_name: str) -> tuple[dict, str]:
- dict: context dictionary for the account settings page, possibly modified.
- str: template name to be rendered by the account settings page, possibly modified.
"""
data: dict = super().run_pipeline(context=context, template_name=template_name)
data = super().run_pipeline(context=context, template_name=template_name)
return data.get("context"), data.get("template_name")


Expand All @@ -128,8 +128,8 @@ class StudentRegistrationRequested(OpenEdxPublicFilter, SensitiveDataManagementM
- Function or Method: RegistrationView.post
"""

filter_type: str = "org.openedx.learning.student.registration.requested.v1"
sensitive_form_data: list[str] = [
filter_type = "org.openedx.learning.student.registration.requested.v1"
sensitive_form_data = [
"password",
"newpassword",
"new_password",
Expand Down Expand Up @@ -181,7 +181,7 @@ class StudentLoginRequested(OpenEdxPublicFilter):
- Function or Method: login_user
"""

filter_type: str = "org.openedx.learning.student.login.requested.v1"
filter_type = "org.openedx.learning.student.login.requested.v1"

class PreventLogin(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -238,7 +238,7 @@ class CourseEnrollmentStarted(OpenEdxPublicFilter):
- Function or Method: enroll
"""

filter_type: str = "org.openedx.learning.course.enrollment.started.v1"
filter_type = "org.openedx.learning.course.enrollment.started.v1"

class PreventEnrollment(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -286,7 +286,7 @@ class CourseUnenrollmentStarted(OpenEdxPublicFilter):
- Function or Method: unenroll
"""

filter_type: str = "org.openedx.learning.course.unenrollment.started.v1"
filter_type = "org.openedx.learning.course.unenrollment.started.v1"

class PreventUnenrollment(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -333,7 +333,7 @@ class CertificateCreationRequested(OpenEdxPublicFilter):
- Function or Method: _generate_certificate_task
"""

filter_type:str = "org.openedx.learning.certificate.creation.requested.v1"
filter_type = "org.openedx.learning.certificate.creation.requested.v1"

class PreventCertificateCreation(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -407,7 +407,7 @@ class CertificateRenderStarted(OpenEdxPublicFilter):
- Function or Method: render_html_view
"""

filter_type: str = "org.openedx.learning.certificate.render.started.v1"
filter_type = "org.openedx.learning.certificate.render.started.v1"

class RedirectToPage(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -494,7 +494,7 @@ class CohortChangeRequested(OpenEdxPublicFilter):
- Function or Method: assign
"""

filter_type: str = "org.openedx.learning.cohort.change.requested.v1"
filter_type = "org.openedx.learning.cohort.change.requested.v1"

class PreventCohortChange(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -538,7 +538,7 @@ class CohortAssignmentRequested(OpenEdxPublicFilter):
- Function or Method: assign
"""

filter_type: str = "org.openedx.learning.cohort.assignment.requested.v1"
filter_type = "org.openedx.learning.cohort.assignment.requested.v1"

class PreventCohortAssignment(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -582,7 +582,7 @@ class CourseAboutRenderStarted(OpenEdxPublicFilter):
- Function or Method: course_about
"""

filter_type: str = "org.openedx.learning.course_about.render.started.v1"
filter_type = "org.openedx.learning.course_about.render.started.v1"

class RedirectToPage(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -683,7 +683,7 @@ class DashboardRenderStarted(OpenEdxPublicFilter):
This filter doesn't work alongside the dashboard MFE, only with the legacy student dashboard.
"""

filter_type: str = "org.openedx.learning.dashboard.render.started.v1"
filter_type = "org.openedx.learning.dashboard.render.started.v1"

class RedirectToPage(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -779,7 +779,7 @@ class VerticalBlockChildRenderStarted(OpenEdxPublicFilter):
- Function or Method: VerticalBlock._student_or_public_view
"""

filter_type: str = "org.openedx.learning.vertical_block_child.render.started.v1"
filter_type = "org.openedx.learning.vertical_block_child.render.started.v1"

class PreventChildBlockRender(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -825,7 +825,7 @@ class CourseEnrollmentQuerysetRequested(OpenEdxPublicFilter):
marked to be removed if it's not used. See openedx-filters#245 for more information.
"""

filter_type: str = "org.openedx.learning.course_enrollment_queryset.requested.v1"
filter_type = "org.openedx.learning.course_enrollment_queryset.requested.v1"

class PreventEnrollmentQuerysetRequest(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -864,7 +864,7 @@ class RenderXBlockStarted(OpenEdxPublicFilter):
- Function or Method: render_xblock
"""

filter_type: str = "org.openedx.learning.xblock.render.started.v1"
filter_type = "org.openedx.learning.xblock.render.started.v1"

class PreventXBlockBlockRender(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -925,7 +925,7 @@ class VerticalBlockRenderCompleted(OpenEdxPublicFilter):
- Function or Method: VerticalBlock._student_or_public_view
"""

filter_type: str = "org.openedx.learning.vertical_block.render.completed.v1"
filter_type = "org.openedx.learning.vertical_block.render.completed.v1"

class PreventVerticalBlockRender(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -973,7 +973,7 @@ class CourseHomeUrlCreationStarted(OpenEdxPublicFilter):
- Function or Method: course_home_url
"""

filter_type: str = "org.openedx.learning.course.homepage.url.creation.started.v1"
filter_type = "org.openedx.learning.course.homepage.url.creation.started.v1"

@classmethod
def run_filter(cls, course_key: CourseKey, course_home_url: str) -> tuple[CourseKey, str]:
Expand Down Expand Up @@ -1010,7 +1010,7 @@ class CourseEnrollmentAPIRenderStarted(OpenEdxPublicFilter):
- Function or Method: EnrollmentSerializer.to_representation
"""

filter_type: str = "org.openedx.learning.home.enrollment.api.rendered.v1"
filter_type = "org.openedx.learning.home.enrollment.api.rendered.v1"

@classmethod
def run_filter(cls, course_key: CourseKey, serialized_enrollment: dict) -> tuple[CourseKey, dict]:
Expand Down Expand Up @@ -1047,7 +1047,7 @@ class CourseRunAPIRenderStarted(OpenEdxPublicFilter):
- Function or Method: CourseRunSerializer.to_representation
"""

filter_type: str = "org.openedx.learning.home.courserun.api.rendered.started.v1"
filter_type = "org.openedx.learning.home.courserun.api.rendered.started.v1"

@classmethod
def run_filter(cls, serialized_courserun: dict) -> dict:
Expand Down Expand Up @@ -1081,7 +1081,7 @@ class InstructorDashboardRenderStarted(OpenEdxPublicFilter):
- Function or Method: instructor_dashboard_2
"""

filter_type: str = "org.openedx.learning.instructor.dashboard.render.started.v1"
filter_type = "org.openedx.learning.instructor.dashboard.render.started.v1"

class RedirectToPage(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -1179,7 +1179,7 @@ class ORASubmissionViewRenderStarted(OpenEdxPublicFilter):
- Function or Method: render_submission
"""

filter_type: str = "org.openedx.learning.ora.submission_view.render.started.v1"
filter_type = "org.openedx.learning.ora.submission_view.render.started.v1"

class RenderInvalidTemplate(OpenEdxFilterException):
"""
Expand Down Expand Up @@ -1237,7 +1237,7 @@ class IDVPageURLRequested(OpenEdxPublicFilter):
- Function or Method: XBlockVerificationService.get_verify_location
"""

filter_type: str = "org.openedx.learning.idv.page.url.requested.v1"
filter_type = "org.openedx.learning.idv.page.url.requested.v1"

@classmethod
def run_filter(cls, url: str) -> str:
Expand Down Expand Up @@ -1271,7 +1271,7 @@ class CourseAboutPageURLRequested(OpenEdxPublicFilter):
- Function or Method: get_link_for_about_page
"""

filter_type: str = "org.openedx.learning.course_about.page.url.requested.v1"
filter_type = "org.openedx.learning.course_about.page.url.requested.v1"

@classmethod
def run_filter(cls, url: str, org: str) -> tuple[str, str]:
Expand Down Expand Up @@ -1309,7 +1309,7 @@ class ScheduleQuerySetRequested(OpenEdxPublicFilter):
- Function or Method: BinnedSchedulesBaseResolver.get_schedules_with_target_date_by_bin_and_orgs
"""

filter_type: str = "org.openedx.learning.schedule.queryset.requested.v1"
filter_type = "org.openedx.learning.schedule.queryset.requested.v1"

@classmethod
def run_filter(cls, schedules: QuerySet) -> QuerySet:
Expand Down
16 changes: 8 additions & 8 deletions openedx_filters/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tooling necessary to use Open edX Filters.
"""
from logging import getLogger
from typing import Any, Optional
from typing import Any, Union

from django.conf import settings
from django.utils.module_loading import import_string
Expand All @@ -26,7 +26,7 @@ def __repr__(self) -> str:
return "<OpenEdxPublicFilter: {filter_type}>".format(filter_type=self.filter_type)

@classmethod
def get_steps_for_pipeline(cls, pipeline: list, fail_silently: Optional[bool] = True) -> list:
def get_steps_for_pipeline(cls, pipeline: list, fail_silently: bool = True) -> list:
"""
Get pipeline objects from paths.
Expand Down Expand Up @@ -96,11 +96,9 @@ def get_pipeline_configuration(cls) -> tuple[list, bool, dict]:
False the opposite.
extra_config: anything else defined in the dictionary.
"""
filter_config: dict = cls.get_filter_config()
filter_config = cls.get_filter_config()

pipeline: list = []
fail_silently: bool = True
extra_config: dict = {}
pipeline, fail_silently, extra_config = [], True, {}

if not filter_config:
return pipeline, fail_silently, extra_config
Expand Down Expand Up @@ -201,12 +199,14 @@ def run_pipeline(cls, **kwargs: Any) -> dict:
information check their Github repository:
https://github.com/python-social-auth/social-core
"""
pipeline, fail_silently, extra_config = cls.get_pipeline_configuration()
pipeline: list[str] = []
fail_silently: bool = True
extra_config: dict[str, Any] = {}

if not pipeline:
return kwargs

steps = cls.get_steps_for_pipeline(pipeline, fail_silently)
steps: list[] = cls.get_steps_for_pipeline(pipeline, fail_silently)
filter_metadata = {
"filter_type": cls.filter_type,
"running_pipeline": pipeline,
Expand Down
6 changes: 3 additions & 3 deletions openedx_filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SensitiveDataManagementMixin:
Custom class used manage sensitive data within filter arguments.
"""

sensitive_form_data: list[str] = []
sensitive_form_data = []

@classmethod
def extract_sensitive_data(cls, form_data: QueryDict) -> dict:
Expand All @@ -28,8 +28,8 @@ def extract_sensitive_data(cls, form_data: QueryDict) -> dict:
>> form_data
{"username": "example"}
"""
sensitive_data: dict = {}
base_form_data: QueryDict = form_data.copy()
sensitive_data = {}
base_form_data = form_data.copy()
for key, value in base_form_data.items():
if key in cls.sensitive_form_data:
form_data.pop(key)
Expand Down
26 changes: 24 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ asgiref==3.8.1
# via
# -r requirements/quality.txt
# django
# django-stubs
astroid==3.3.8
# via
# -r requirements/quality.txt
Expand All @@ -25,7 +26,7 @@ cachetools==5.5.1
# via
# -r requirements/ci.txt
# tox
certifi==2024.12.14
certifi==2025.1.31
# via
# -r requirements/quality.txt
# requests
Expand Down Expand Up @@ -72,7 +73,7 @@ cryptography==44.0.0
# secretstorage
ddt==1.7.2
# via -r requirements/quality.txt
diff-cover==9.2.1
diff-cover==9.2.2
# via -r requirements/dev.in
dill==0.3.9
# via
Expand All @@ -86,6 +87,14 @@ django==4.2.18
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/quality.txt
# django-stubs
# django-stubs-ext
django-stubs==5.1.2
# via -r requirements/quality.txt
django-stubs-ext==5.1.2
# via
# -r requirements/quality.txt
# django-stubs
dnspython==2.7.0
# via
# -r requirements/quality.txt
Expand Down Expand Up @@ -170,6 +179,12 @@ more-itertools==10.6.0
# -r requirements/quality.txt
# jaraco-classes
# jaraco-functools
mypy==1.14.1
# via -r requirements/quality.txt
mypy-extensions==1.0.0
# via
# -r requirements/quality.txt
# mypy
nh3==0.2.20
# via
# -r requirements/quality.txt
Expand Down Expand Up @@ -323,10 +338,17 @@ tox==4.24.1
# via -r requirements/ci.txt
twine==6.1.0
# via -r requirements/quality.txt
types-pyyaml==6.0.12.20241230
# via
# -r requirements/quality.txt
# django-stubs
typing-extensions==4.12.2
# via
# -r requirements/quality.txt
# django-stubs
# django-stubs-ext
# edx-opaque-keys
# mypy
urllib3==2.2.3
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
Expand Down
Loading

0 comments on commit 93e0105

Please sign in to comment.