From ae2a07bcb78c9ce10c42396a7530a7d594f1ecf2 Mon Sep 17 00:00:00 2001 From: Jimmy Ihalainen Date: Thu, 5 Dec 2024 10:40:02 +0200 Subject: [PATCH] Fix lint errors --- .prospector.yaml | 1 + exercise/cache/basetypes.py | 5 ++--- exercise/cache/points.py | 3 ++- exercise/staff_views.py | 1 + external_services/api/tests.py | 1 + lint.sh | 11 +++++++++-- selenium_test/test/page_objects.py | 2 ++ 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.prospector.yaml b/.prospector.yaml index 5bcd9778d..f76ed38b4 100644 --- a/.prospector.yaml +++ b/.prospector.yaml @@ -28,6 +28,7 @@ pylint: - relative-beyond-top-level - cyclic-import - imported-auth-user + - too-many-positional-arguments options: jobs: 0 diff --git a/exercise/cache/basetypes.py b/exercise/cache/basetypes.py index c9a7f1054..463ccbea5 100644 --- a/exercise/cache/basetypes.py +++ b/exercise/cache/basetypes.py @@ -36,7 +36,7 @@ class EqById: id: int def __eq__(self, other: Any) -> bool: - if type(self) != type(other): # pylint: disable=unidiomatic-typecheck + if type(self) != type(other): # pylint: disable=unidiomatic-typecheck # noqa: E721 return False return self.id == other.id @@ -573,8 +573,7 @@ def _generate_data( # pylint: disable=too-many-locals _add_to(categories[entry.category_id], exercise) _add_to(total, exercise) - if exercise.max_group_size > total.max_group_size: - total.max_group_size = exercise.max_group_size + total.max_group_size = max(total.max_group_size, exercise.max_group_size) if exercise.max_group_size > 1 and exercise.min_group_size < total.min_group_size: total.min_group_size = exercise.min_group_size diff --git a/exercise/cache/points.py b/exercise/cache/points.py index 8ca597d3a..276b86b12 100644 --- a/exercise/cache/points.py +++ b/exercise/cache/points.py @@ -587,7 +587,8 @@ class ExercisePoints(LearningObjectPoints): (Notification, [post_delete, post_save], with_user_ids(model_exercise_siblings_confirms_the_level)), ] DBCLS = LearningObjectPoints.DBCLS - submissions: List[SubmissionEntry] = field(default_factory=list) + # field() works because LearningObjectPoints inherits CommonPointData, which is a dataclass + submissions: List[SubmissionEntry] = field(default_factory=list) # pylint: disable=invalid-field-call _true_best_submission: Optional[SubmissionEntry] _best_submission: Optional[SubmissionEntry] graded: bool diff --git a/exercise/staff_views.py b/exercise/staff_views.py index b42b12542..c825d5292 100644 --- a/exercise/staff_views.py +++ b/exercise/staff_views.py @@ -255,6 +255,7 @@ def get_common_objects(self) -> None: elif self.exercise.grading_mode == BaseExercise.GRADING_MODE.LAST: mode = _('GRADING_MODE_LAST') else: + mode = _('UNKNOWN') logger.warning("Missing description for grading mode.") self.grading_mode_text = format_lazy(_('GRADING_MODE_TITLE -- {}'), mode) diff --git a/external_services/api/tests.py b/external_services/api/tests.py index 4c5840c5f..d5f47cbe5 100644 --- a/external_services/api/tests.py +++ b/external_services/api/tests.py @@ -128,6 +128,7 @@ def mk_sourced_id(self, lti_exercise, user=None, enrollment=None): elif user and not lti_exercise.lti_service.is_anonymous: user_id = 'i' + str(user.pk) else: + user_id = 'unknown' self.fail('mk_sourced_id requires the enrollment argument for anonymous LTI services and user otherwise.') return '{}-{}'.format(lti_exercise.pk, user_id) diff --git a/lint.sh b/lint.sh index e0857860c..f59f9b726 100755 --- a/lint.sh +++ b/lint.sh @@ -1,4 +1,11 @@ #!/bin/bash -docker build -f .github/workflows/lint.Dockerfile -q . -t aplus_prospector -docker run --rm -v ${PWD}:/app -w /app aplus_prospector sh -c 'prospector' +# Build the image if it doesn't exist yet +if [ -z "$(docker images -q aplus_prospector 2> /dev/null)" ]; then + echo "Building prospector image..." + docker build -f .github/workflows/lint.Dockerfile -q . -t aplus_prospector +else + echo "Using existing prospector image." +fi +echo "Running prospector..." +docker run --rm -v "${PWD}":/app -w /app aplus_prospector sh -c 'prospector' diff --git a/selenium_test/test/page_objects.py b/selenium_test/test/page_objects.py index 263b646eb..9fafa8553 100644 --- a/selenium_test/test/page_objects.py +++ b/selenium_test/test/page_objects.py @@ -224,6 +224,8 @@ def __init__(self, driver, course=CourseName.APLUS): path = "/aplus1/basic_instance" elif (course == CourseName.HOOK): path = "/aplus1/hook_instance" + else: + raise Exception(f"Unknown course: {course}") # pylint: disable=broad-exception-raised self.load(path, HomePageLocators.MAIN_SCORE)