diff --git a/.github/workflows/pylint-checks.yml b/.github/workflows/pylint-checks.yml index e71fd3811f..780d98f2a9 100644 --- a/.github/workflows/pylint-checks.yml +++ b/.github/workflows/pylint-checks.yml @@ -14,20 +14,19 @@ jobs: matrix: include: - module-name: lms-1 - path: "lms/djangoapps/badges/ lms/djangoapps/branding/ lms/djangoapps/bulk_email/ lms/djangoapps/bulk_enroll/ lms/djangoapps/bulk_user_retirement/ lms/djangoapps/ccx/ lms/djangoapps/certificates/ lms/djangoapps/commerce/ lms/djangoapps/course_api/ lms/djangoapps/course_blocks/ lms/djangoapps/course_home_api/ lms/djangoapps/course_wiki/ lms/djangoapps/coursewarehistoryextended/ lms/djangoapps/debug/ lms/djangoapps/courseware/ lms/djangoapps/course_goals/ lms/djangoapps/rss_proxy/ lms/djangoapps/save_for_later/" + path: "--django-settings-module=lms.envs.test lms/djangoapps/badges/ lms/djangoapps/branding/ lms/djangoapps/bulk_email/ lms/djangoapps/bulk_enroll/ lms/djangoapps/bulk_user_retirement/ lms/djangoapps/ccx/ lms/djangoapps/certificates/ lms/djangoapps/commerce/ lms/djangoapps/course_api/ lms/djangoapps/course_blocks/ lms/djangoapps/course_home_api/ lms/djangoapps/course_wiki/ lms/djangoapps/coursewarehistoryextended/ lms/djangoapps/debug/ lms/djangoapps/courseware/ lms/djangoapps/course_goals/ lms/djangoapps/rss_proxy/ lms/djangoapps/save_for_later/" - module-name: lms-2 - path: "lms/djangoapps/gating/ lms/djangoapps/grades/ lms/djangoapps/instructor/ lms/djangoapps/instructor_analytics/ lms/djangoapps/discussion/ lms/djangoapps/edxnotes/ lms/djangoapps/email_marketing/ lms/djangoapps/experiments/ lms/djangoapps/instructor_task/ lms/djangoapps/learner_dashboard/ lms/djangoapps/learner_home/ lms/djangoapps/lms_initialization/ lms/djangoapps/lms_xblock/ lms/djangoapps/lti_provider/ lms/djangoapps/mailing/ lms/djangoapps/mobile_api/ lms/djangoapps/monitoring/ lms/djangoapps/ora_staff_grader/ lms/djangoapps/program_enrollments/ lms/djangoapps/rss_proxy lms/djangoapps/static_template_view/ lms/djangoapps/staticbook/ lms/djangoapps/support/ lms/djangoapps/survey/ lms/djangoapps/teams/ lms/djangoapps/tests/ lms/djangoapps/user_tours/ lms/djangoapps/verify_student/ lms/djangoapps/mfe_config_api/ lms/envs/ lms/lib/ lms/tests.py" + path: "--django-settings-module=lms.envs.test lms/djangoapps/gating/ lms/djangoapps/grades/ lms/djangoapps/instructor/ lms/djangoapps/instructor_analytics/ lms/djangoapps/discussion/ lms/djangoapps/edxnotes/ lms/djangoapps/email_marketing/ lms/djangoapps/experiments/ lms/djangoapps/instructor_task/ lms/djangoapps/learner_dashboard/ lms/djangoapps/learner_home/ lms/djangoapps/lms_initialization/ lms/djangoapps/lms_xblock/ lms/djangoapps/lti_provider/ lms/djangoapps/mailing/ lms/djangoapps/mobile_api/ lms/djangoapps/monitoring/ lms/djangoapps/ora_staff_grader/ lms/djangoapps/program_enrollments/ lms/djangoapps/rss_proxy lms/djangoapps/static_template_view/ lms/djangoapps/staticbook/ lms/djangoapps/support/ lms/djangoapps/survey/ lms/djangoapps/teams/ lms/djangoapps/tests/ lms/djangoapps/user_tours/ lms/djangoapps/verify_student/ lms/djangoapps/mfe_config_api/ lms/envs/ lms/lib/ lms/tests.py" - module-name: openedx-1 - path: "openedx/core/types/ openedx/core/djangoapps/ace_common/ openedx/core/djangoapps/agreements/ openedx/core/djangoapps/api_admin/ openedx/core/djangoapps/auth_exchange/ openedx/core/djangoapps/bookmarks/ openedx/core/djangoapps/cache_toolbox/ openedx/core/djangoapps/catalog/ openedx/core/djangoapps/ccxcon/ openedx/core/djangoapps/commerce/ openedx/core/djangoapps/common_initialization/ openedx/core/djangoapps/common_views/ openedx/core/djangoapps/config_model_utils/ openedx/core/djangoapps/content/ openedx/core/djangoapps/content_libraries/ openedx/core/djangoapps/contentserver/ openedx/core/djangoapps/cookie_metadata/ openedx/core/djangoapps/cors_csrf/ openedx/core/djangoapps/course_apps/ openedx/core/djangoapps/course_date_signals/ openedx/core/djangoapps/course_groups/ openedx/core/djangoapps/courseware_api/ openedx/core/djangoapps/crawlers/ openedx/core/djangoapps/credentials/ openedx/core/djangoapps/credit/ openedx/core/djangoapps/dark_lang/ openedx/core/djangoapps/debug/ openedx/core/djangoapps/demographics/ openedx/core/djangoapps/discussions/ openedx/core/djangoapps/django_comment_common/ openedx/core/djangoapps/embargo/ openedx/core/djangoapps/enrollments/ openedx/core/djangoapps/external_user_ids/ openedx/core/djangoapps/zendesk_proxy/ openedx/core/djangolib/ openedx/core/lib/ openedx/core/tests/ openedx/core/djangoapps/course_live/" + path: "--django-settings-module=lms.envs.test openedx/core/types/ openedx/core/djangoapps/ace_common/ openedx/core/djangoapps/agreements/ openedx/core/djangoapps/api_admin/ openedx/core/djangoapps/auth_exchange/ openedx/core/djangoapps/bookmarks/ openedx/core/djangoapps/cache_toolbox/ openedx/core/djangoapps/catalog/ openedx/core/djangoapps/ccxcon/ openedx/core/djangoapps/commerce/ openedx/core/djangoapps/common_initialization/ openedx/core/djangoapps/common_views/ openedx/core/djangoapps/config_model_utils/ openedx/core/djangoapps/content/ openedx/core/djangoapps/content_libraries/ openedx/core/djangoapps/contentserver/ openedx/core/djangoapps/cookie_metadata/ openedx/core/djangoapps/cors_csrf/ openedx/core/djangoapps/course_apps/ openedx/core/djangoapps/course_date_signals/ openedx/core/djangoapps/course_groups/ openedx/core/djangoapps/courseware_api/ openedx/core/djangoapps/crawlers/ openedx/core/djangoapps/credentials/ openedx/core/djangoapps/credit/ openedx/core/djangoapps/dark_lang/ openedx/core/djangoapps/debug/ openedx/core/djangoapps/demographics/ openedx/core/djangoapps/discussions/ openedx/core/djangoapps/django_comment_common/ openedx/core/djangoapps/embargo/ openedx/core/djangoapps/enrollments/ openedx/core/djangoapps/external_user_ids/ openedx/core/djangoapps/zendesk_proxy/ openedx/core/djangolib/ openedx/core/lib/ openedx/core/tests/ openedx/core/djangoapps/course_live/" - module-name: openedx-2 - path: "openedx/core/djangoapps/geoinfo/ openedx/core/djangoapps/header_control/ openedx/core/djangoapps/heartbeat/ openedx/core/djangoapps/lang_pref/ openedx/core/djangoapps/models/ openedx/core/djangoapps/monkey_patch/ openedx/core/djangoapps/oauth_dispatch/ openedx/core/djangoapps/olx_rest_api/ openedx/core/djangoapps/password_policy/ openedx/core/djangoapps/plugin_api/ openedx/core/djangoapps/plugins/ openedx/core/djangoapps/profile_images/ openedx/core/djangoapps/programs/ openedx/core/djangoapps/safe_sessions/ openedx/core/djangoapps/schedules/ openedx/core/djangoapps/service_status/ openedx/core/djangoapps/session_inactivity_timeout/ openedx/core/djangoapps/signals/ openedx/core/djangoapps/site_configuration/ openedx/core/djangoapps/system_wide_roles/ openedx/core/djangoapps/theming/ openedx/core/djangoapps/user_api/ openedx/core/djangoapps/user_authn/ openedx/core/djangoapps/util/ openedx/core/djangoapps/verified_track_content/ openedx/core/djangoapps/video_config/ openedx/core/djangoapps/video_pipeline/ openedx/core/djangoapps/waffle_utils/ openedx/core/djangoapps/xblock/ openedx/core/djangoapps/xmodule_django/ openedx/core/tests/ openedx/features/ openedx/testing/ openedx/tests/ openedx/core/djangoapps/learner_pathway/" + path: "--django-settings-module=lms.envs.test openedx/core/djangoapps/geoinfo/ openedx/core/djangoapps/header_control/ openedx/core/djangoapps/heartbeat/ openedx/core/djangoapps/lang_pref/ openedx/core/djangoapps/models/ openedx/core/djangoapps/monkey_patch/ openedx/core/djangoapps/oauth_dispatch/ openedx/core/djangoapps/olx_rest_api/ openedx/core/djangoapps/password_policy/ openedx/core/djangoapps/plugin_api/ openedx/core/djangoapps/plugins/ openedx/core/djangoapps/profile_images/ openedx/core/djangoapps/programs/ openedx/core/djangoapps/safe_sessions/ openedx/core/djangoapps/schedules/ openedx/core/djangoapps/service_status/ openedx/core/djangoapps/session_inactivity_timeout/ openedx/core/djangoapps/signals/ openedx/core/djangoapps/site_configuration/ openedx/core/djangoapps/system_wide_roles/ openedx/core/djangoapps/theming/ openedx/core/djangoapps/user_api/ openedx/core/djangoapps/user_authn/ openedx/core/djangoapps/util/ openedx/core/djangoapps/verified_track_content/ openedx/core/djangoapps/video_config/ openedx/core/djangoapps/video_pipeline/ openedx/core/djangoapps/waffle_utils/ openedx/core/djangoapps/xblock/ openedx/core/djangoapps/xmodule_django/ openedx/core/tests/ openedx/features/ openedx/testing/ openedx/tests/ openedx/core/djangoapps/learner_pathway/" - module-name: common - path: "common" + path: "--django-settings-module=lms.envs.test common" - module-name: cms - path: "cms" + path: "--django-settings-module=cms.envs.test cms" - module-name: xmodule - path: "xmodule" - + path: "--django-settings-module=lms.envs.test xmodule" name: pylint ${{ matrix.module-name }} steps: diff --git a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py index c76837912d..af92a3313a 100644 --- a/cms/djangoapps/contentstore/tests/test_course_create_rerun.py +++ b/cms/djangoapps/contentstore/tests/test_course_create_rerun.py @@ -83,7 +83,7 @@ class TestCourseListing(ModuleStoreTestCase): Reverse the setup """ self.client.logout() - ModuleStoreTestCase.tearDown(self) + ModuleStoreTestCase.tearDown(self) # pylint: disable=non-parent-method-called def test_rerun(self): """ diff --git a/cms/djangoapps/contentstore/tests/test_course_listing.py b/cms/djangoapps/contentstore/tests/test_course_listing.py index 44fe762f73..621c932787 100644 --- a/cms/djangoapps/contentstore/tests/test_course_listing.py +++ b/cms/djangoapps/contentstore/tests/test_course_listing.py @@ -87,7 +87,7 @@ class TestCourseListing(ModuleStoreTestCase): Reverse the setup """ self.client.logout() - ModuleStoreTestCase.tearDown(self) + ModuleStoreTestCase.tearDown(self) # pylint: disable=non-parent-method-called def test_empty_course_listing(self): """ diff --git a/cms/djangoapps/contentstore/tests/test_permissions.py b/cms/djangoapps/contentstore/tests/test_permissions.py index 5b61ced685..7f0a7079dd 100644 --- a/cms/djangoapps/contentstore/tests/test_permissions.py +++ b/cms/djangoapps/contentstore/tests/test_permissions.py @@ -62,7 +62,7 @@ class TestCourseAccess(ModuleStoreTestCase): Reverse the setup """ self.client.logout() - ModuleStoreTestCase.tearDown(self) + ModuleStoreTestCase.tearDown(self) # pylint: disable=non-parent-method-called def test_get_all_users(self): """ diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 2f6a6a0c6f..55464820d0 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -1206,10 +1206,10 @@ def settings_handler(request, course_key_string): # lint-amnesty, pylint: disab if is_prerequisite_courses_enabled(): courses, in_process_course_actions = get_courses_accessible_to_user(request) # exclude current course from the list of available courses - courses = (course for course in courses if course.id != course_key) + courses = [course for course in courses if course.id != course_key] if courses: courses, __ = _process_courses_list(courses, in_process_course_actions) - settings_context.update({'possible_pre_requisite_courses': list(courses)}) + settings_context.update({'possible_pre_requisite_courses': courses}) if credit_eligibility_enabled: if is_credit_course(course_key): diff --git a/common/djangoapps/student/tests/test_email.py b/common/djangoapps/student/tests/test_email.py index 914a26e4bf..2da25b67cc 100644 --- a/common/djangoapps/student/tests/test_email.py +++ b/common/djangoapps/student/tests/test_email.py @@ -244,7 +244,7 @@ class ProctoringRequirementsEmailTests(EmailTemplateTagMixin, ModuleStoreTestCas self.course = None self.user = UserFactory() - @ddt.data('course_run_1', 'matt''s course', 'matt's run') + @ddt.data('course_run_1', 'matt\'s course', 'matt's run') def test_send_proctoring_requirements_email(self, course_run_name): self.course = CourseFactory( display_name=course_run_name, diff --git a/lms/djangoapps/course_api/blocks/transformers/block_counts.py b/lms/djangoapps/course_api/blocks/transformers/block_counts.py index 87254719e8..b2eebbcbb3 100644 --- a/lms/djangoapps/course_api/blocks/transformers/block_counts.py +++ b/lms/djangoapps/course_api/blocks/transformers/block_counts.py @@ -39,10 +39,10 @@ class BlockCountsTransformer(BlockStructureTransformer): for block_key in block_structure.post_order_traversal(): for block_type in self.block_types_to_count: - descendants_type_count = sum([ + descendants_type_count = sum( block_structure.get_transformer_block_field(child_key, self, block_type, 0) for child_key in block_structure.get_children(block_key) - ]) + ) block_structure.set_transformer_block_field( block_key, self, diff --git a/lms/djangoapps/course_blocks/transformers/start_date.py b/lms/djangoapps/course_blocks/transformers/start_date.py index cfcbe179bd..13ba3b7470 100644 --- a/lms/djangoapps/course_blocks/transformers/start_date.py +++ b/lms/djangoapps/course_blocks/transformers/start_date.py @@ -96,15 +96,16 @@ class StartDateTransformer(FilteringTransformerMixin, BlockStructureTransformer) now = datetime.now(UTC) - removal_condition = lambda block_key: not check_start_date( - usage_info.user, - block_structure.get_xblock_field(block_key, 'days_early_for_beta'), - self._get_merged_start_date(block_structure, block_key), - usage_info.course_key, - now=now, - ) + def _removal_condition(block_key): + return not check_start_date( + usage_info.user, + block_structure.get_xblock_field(block_key, 'days_early_for_beta'), + self._get_merged_start_date(block_structure, block_key), + usage_info.course_key, + now=now + ) if usage_info.include_has_scheduled_content: - self._check_has_scheduled_content(block_structure, removal_condition) + self._check_has_scheduled_content(block_structure, _removal_condition) - return [block_structure.create_removal_filter(removal_condition)] + return [block_structure.create_removal_filter(_removal_condition)] diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index c7a9c981a5..411acc5515 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -799,8 +799,9 @@ def sort_by_announcement(courses): """ # Sort courses by how far are they from they start day - key = lambda course: course.sorting_score - courses = sorted(courses, key=key) + def _key(course): + return course.sorting_score + courses = sorted(courses, key=_key) return courses diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index 9e187fd1eb..8dbb5dc936 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -2067,8 +2067,11 @@ class TestModuleTrackingContext(SharedModuleStoreTestCase): """ original_usage_key = UsageKey.from_string('block-v1:A+B+C+type@problem+block@abcd1234') original_usage_version = ObjectId() - mock_get_original_usage = lambda _, key: (original_usage_key, original_usage_version) - with patch('xmodule.modulestore.mixed.MixedModuleStore.get_block_original_usage', mock_get_original_usage): + + def _mock_get_original_usage(_, __): + return original_usage_key, original_usage_version + + with patch('xmodule.modulestore.mixed.MixedModuleStore.get_block_original_usage', _mock_get_original_usage): module_info = self.handle_callback_and_get_module_info(mock_tracker) assert 'original_usage_key' in module_info assert module_info['original_usage_key'] == str(original_usage_key) diff --git a/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py b/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py index 7d85c3f599..847d25490a 100644 --- a/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py +++ b/lms/djangoapps/grades/management/commands/tests/test_compute_grades.py @@ -76,13 +76,16 @@ class TestComputeGrades(SharedModuleStoreTestCase): if not estimate_first_attempted: command.append('--no_estimate_first_attempted') call_command(*(command + courses)) - _kwargs = lambda course_key, offset: { - 'course_key': course_key, - 'batch_size': 2, - 'offset': offset, - 'estimate_first_attempted': estimate_first_attempted, - 'seq_id': ANY, - } + + def _kwargs(course_key, offset): + return { + 'course_key': course_key, + 'batch_size': 2, + 'offset': offset, + 'estimate_first_attempted': estimate_first_attempted, + 'seq_id': ANY + } + actual = mock_task.apply_async.call_args_list # Order doesn't matter, but can't use a set because dicts aren't hashable expected = [ diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index ac7ab1749c..ca38b5ce26 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -438,8 +438,10 @@ class TestInstructorEnrollmentStudentModule(SharedModuleStoreTestCase): module_state_key=msk, state=original_state ) - # lambda to reload the module state from the database - module = lambda: StudentModule.objects.get(student=self.user, course_id=self.course_key, module_state_key=msk) + + def module(): + return StudentModule.objects.get(student=self.user, course_id=self.course_key, module_state_key=msk) + assert json.loads(module().state)['attempts'] == 32 reset_student_attempts(self.course_key, self.user, msk, requesting_user=self.user) assert json.loads(module().state)['attempts'] == 0 diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index 1604a4f85c..ecc3abd8d0 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -343,8 +343,8 @@ def get_metadata_from_index(queryset, text_search=None): type=lib.type, description=metadata[i]['description'], version=metadata[i]['version'], - allow_public_learning=queryset[i].allow_public_learning, - allow_public_read=queryset[i].allow_public_read, + allow_public_learning=lib.allow_public_learning, + allow_public_read=lib.allow_public_read, num_blocks=metadata[i].get('num_blocks'), last_published=metadata[i].get('last_published'), has_unpublished_changes=metadata[i].get('has_unpublished_changes'), diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/models.py b/openedx/core/djangoapps/django_comment_common/comment_client/models.py index d8d7a2eac8..4e602809c8 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/models.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/models.py @@ -122,7 +122,7 @@ class Model: def _update_from_response(self, response_data): for k, v in response_data.items(): if k in self.accessible_fields: - self.__setattr__(k, v) + setattr(self, k, v) else: log.warning( "Unexpected field {field_name} in model {model_name}".format( diff --git a/openedx/core/djangoapps/programs/utils.py b/openedx/core/djangoapps/programs/utils.py index fde07e242a..39b8e60392 100644 --- a/openedx/core/djangoapps/programs/utils.py +++ b/openedx/core/djangoapps/programs/utils.py @@ -392,7 +392,7 @@ class ProgramProgressMeter: certificate ) earliest_course_run_date = min( - [date for date in [available_date, earliest_course_run_date] if date] + date for date in [available_date, earliest_course_run_date] if date ) # If we're missing a cert for a course, the program isn't completed and we should just bail now @@ -400,7 +400,7 @@ class ProgramProgressMeter: return None # Keep the catalog course date if it's the latest one - program_available_date = max([date for date in [earliest_course_run_date, program_available_date] if date]) + program_available_date = max(date for date in [earliest_course_run_date, program_available_date] if date) return program_available_date diff --git a/openedx/core/djangoapps/user_authn/exceptions.py b/openedx/core/djangoapps/user_authn/exceptions.py index 54f208730f..984aa7e4c1 100644 --- a/openedx/core/djangoapps/user_authn/exceptions.py +++ b/openedx/core/djangoapps/user_authn/exceptions.py @@ -23,8 +23,8 @@ class AuthFailedError(Exception): """ Returns a dict representation of the error. """ resp = {'success': False} for attr in ('value', 'redirect', 'redirect_url', 'error_code', 'context'): - if self.__getattribute__(attr): - resp[attr] = self.__getattribute__(attr) + if getattr(self, attr): + resp[attr] = getattr(self, attr) return resp diff --git a/openedx/core/djangolib/testing/utils.py b/openedx/core/djangolib/testing/utils.py index 2aacd444d3..1da4ee26bf 100644 --- a/openedx/core/djangolib/testing/utils.py +++ b/openedx/core/djangolib/testing/utils.py @@ -101,7 +101,7 @@ class CacheIsolationMixin: cls.__old_settings.append(copy.deepcopy(settings.CACHES)) override = override_settings(CACHES=cache_settings) - override.__enter__() + override.__enter__() # pylint: disable=unnecessary-dunder-call cls.__settings_overrides.append(override) assert settings.CACHES == cache_settings diff --git a/openedx/features/effort_estimation/block_transformers.py b/openedx/features/effort_estimation/block_transformers.py index 11efd6fba7..d315aefd06 100644 --- a/openedx/features/effort_estimation/block_transformers.py +++ b/openedx/features/effort_estimation/block_transformers.py @@ -166,10 +166,10 @@ class EffortEstimationTransformer(BlockStructureTransformer): def _gather_child_values(self, block_structure, block_key, field, default=0): """Collects and sums all child values for field.""" - return sum([ + return sum( block_structure.get_xblock_field(child_key, field, default=default) for child_key in block_structure.get_children(block_key) - ]) + ) def _estimate_children_effort(self, _usage_info, block_structure, block_key): """Collects time and activity counts for children.""" diff --git a/pylint_django_settings.py b/pylint_django_settings.py index 5526b43f9e..75ceab2505 100644 --- a/pylint_django_settings.py +++ b/pylint_django_settings.py @@ -29,7 +29,8 @@ class SetDjangoSettingsChecker(BaseChecker): cms_module = False lms_module = False common_module = False - for arg in self.linter.cmdline_parser.largs: + arguments = self.linter.cmdline_parser.parse_args()[1] + for arg in arguments: if arg.startswith('cms'): cms_module = True elif arg.startswith('lms'): diff --git a/pylintrc b/pylintrc index 14b4cc0afb..96b657e46e 100644 --- a/pylintrc +++ b/pylintrc @@ -69,7 +69,7 @@ [MASTER] ignore = ,.git,.tox,migrations,node_modules,.pycharm_helpers persistent = yes -load-plugins = edx_lint.pylint,pylint_django_settings,pylint_django,pylint_celery,pylint_pytest +load-plugins = edx_lint.pylint,pylint_django,pylint_celery,pylint_pytest [MESSAGES CONTROL] enable = @@ -286,7 +286,6 @@ disable = illegal-waffle-usage, logging-fstring-interpolation, - native-string, import-outside-toplevel, inconsistent-return-statements, no-else-break, @@ -308,8 +307,12 @@ disable = unused-argument, unsubscriptable-object, abstract-method, - wrong-import-order, - no-self-use, + not-callable, + unsupported-binary-operation, + missing-timeout, + c-extension-no-member, + no-name-in-module, + unnecessary-lambda-assignment, [REPORTS] output-format = text @@ -406,4 +409,4 @@ int-import-graph = [EXCEPTIONS] overgeneral-exceptions = Exception -# 976a7bc58c47b2957e91b1632c6ea16e0112bc3b +# 567bf30b121db79bc07a7028651f7efa0724e8a4 diff --git a/pylintrc_tweaks b/pylintrc_tweaks index 128e47cf9a..7911c08af9 100644 --- a/pylintrc_tweaks +++ b/pylintrc_tweaks @@ -1,12 +1,10 @@ # pylintrc tweaks for use with edx_lint. [MASTER] ignore+ = ,.git,.tox,migrations,node_modules,.pycharm_helpers -load-plugins = edx_lint.pylint,pylint_django_settings,pylint_django,pylint_celery,pylint_pytest +load-plugins = edx_lint.pylint,pylint_django,pylint_celery,pylint_pytest [MESSAGES CONTROL] disable+ = - # Disable unicode-format-string until we can agree to turn it on. - native-string, # Disable new refactoring suggestions for now, we have more important things to fix first import-outside-toplevel, inconsistent-return-statements, @@ -29,7 +27,12 @@ disable+ = unused-argument, unsubscriptable-object, abstract-method, - no-self-use, + not-callable, + unsupported-binary-operation, + missing-timeout, + c-extension-no-member, + no-name-in-module, + unnecessary-lambda-assignment, [BASIC] attr-rgx = [a-z_][a-z0-9_]{2,40}$ diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 6bbc41429b..e764d4a12a 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -52,9 +52,6 @@ django-webpack-loader==0.7.0 # version of py2neo will work with Neo4j 3.5. py2neo<2022 -# pylint==2.14.0 is causing test failures -pylint==2.13.9 - # scipy version 1.8 requires numpy>=1.17.3, we've pinned numpy to <1.17.0 in requirements/edx-sandbox/py38.in scipy<1.8.0 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index b20005e8ef..9ad9d0c089 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -51,7 +51,7 @@ asn1crypto==1.5.1 # -r requirements/edx/testing.txt # oscrypto # snowflake-connector-python -astroid==2.11.7 +astroid==2.12.10 # via # -r requirements/edx/testing.txt # pylint @@ -1150,9 +1150,8 @@ pylatexenc==2.10 # via # -r requirements/edx/testing.txt # olxcleaner -pylint==2.13.9 +pylint==2.15.3 # via - # -c requirements/edx/../constraints.txt # -r requirements/edx/testing.txt # edx-lint # pylint-celery @@ -1556,6 +1555,10 @@ tomli==2.0.1 # pylint # pytest # tox +tomlkit==0.11.5 + # via + # -r requirements/edx/testing.txt + # pylint tox==3.26.0 # via # -r requirements/edx/testing.txt diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index b925cfc096..b42e7b733d 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -47,7 +47,7 @@ asn1crypto==1.5.1 # -r requirements/edx/base.txt # oscrypto # snowflake-connector-python -astroid==2.11.7 +astroid==2.12.10 # via # pylint # pylint-celery @@ -1088,9 +1088,8 @@ pylatexenc==2.10 # via # -r requirements/edx/base.txt # olxcleaner -pylint==2.13.9 +pylint==2.15.3 # via - # -c requirements/edx/../constraints.txt # edx-lint # pylint-celery # pylint-django @@ -1445,6 +1444,8 @@ tomli==2.0.1 # pylint # pytest # tox +tomlkit==0.11.5 + # via pylint tox==3.26.0 # via # -r requirements/edx/testing.in diff --git a/xmodule/capa/correctmap.py b/xmodule/capa/correctmap.py index dcbaaff433..8ab1d890f3 100644 --- a/xmodule/capa/correctmap.py +++ b/xmodule/capa/correctmap.py @@ -91,7 +91,7 @@ class CorrectMap(object): """ # empty current dict - self.__init__() + self.__init__() # pylint: disable=unnecessary-dunder-call if not correct_map: return diff --git a/xmodule/capa/responsetypes.py b/xmodule/capa/responsetypes.py index 39000c544a..5c7589e540 100644 --- a/xmodule/capa/responsetypes.py +++ b/xmodule/capa/responsetypes.py @@ -726,8 +726,8 @@ class ChoiceResponse(LoncapaResponse): edc_max_grade = len(all_choices) edc_current_grade = 0 - good_answers = sum([1 for answer in student_answer if answer in self.correct_choices]) - good_non_answers = sum([1 for blank in student_non_answers if blank in self.incorrect_choices]) + good_answers = sum(1 for answer in student_answer if answer in self.correct_choices) + good_non_answers = sum(1 for blank in student_non_answers if blank in self.incorrect_choices) edc_current_grade = good_answers + good_non_answers return_grade = round_away_from_zero(self.get_max_score() * float(edc_current_grade) / float(edc_max_grade), 2) @@ -759,8 +759,8 @@ class ChoiceResponse(LoncapaResponse): halves_error_count = 0 - incorrect_answers = sum([1 for answer in student_answer if answer in self.incorrect_choices]) - missed_answers = sum([1 for blank in student_non_answers if blank in self.correct_choices]) + incorrect_answers = sum(1 for answer in student_answer if answer in self.incorrect_choices) + missed_answers = sum(1 for blank in student_non_answers if blank in self.correct_choices) halves_error_count = incorrect_answers + missed_answers if halves_error_count == 0: diff --git a/xmodule/capa/tests/test_responsetypes.py b/xmodule/capa/tests/test_responsetypes.py index 788a0fd249..afcd60abea 100644 --- a/xmodule/capa/tests/test_responsetypes.py +++ b/xmodule/capa/tests/test_responsetypes.py @@ -970,7 +970,7 @@ class CodeResponseTest(ResponseTest): # pylint: disable=missing-class-docstring cmap = CorrectMap() for i, answer_id in enumerate(answer_ids): queuestate = CodeResponseTest.make_queuestate(i, datetime.now(UTC)) - cmap.update(CorrectMap(answer_id=answer_ids[i], queuestate=queuestate)) + cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate)) self.problem.correct_map.update(cmap) assert self.problem.is_queued() is True @@ -986,7 +986,7 @@ class CodeResponseTest(ResponseTest): # pylint: disable=missing-class-docstring for i, answer_id in enumerate(answer_ids): queuekey = 1000 + i queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(UTC)) - old_cmap.update(CorrectMap(answer_id=answer_ids[i], queuestate=queuestate)) + old_cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate)) # Message format common to external graders grader_msg = 'MESSAGE' # Must be valid XML @@ -1102,7 +1102,7 @@ class CodeResponseTest(ResponseTest): # pylint: disable=missing-class-docstring for i, answer_id in enumerate(answer_ids): queuekey = 1000 + i queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(UTC)) - old_cmap.update(CorrectMap(answer_id=answer_ids[i], queuestate=queuestate)) + old_cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate)) for grader_msg in valid_grader_msgs: correct_score_msg = json.dumps({'correct': True, 'score': 1, 'msg': grader_msg}) diff --git a/xmodule/modulestore/tests/django_utils.py b/xmodule/modulestore/tests/django_utils.py index f5e6ffb348..e2f8aa2be6 100644 --- a/xmodule/modulestore/tests/django_utils.py +++ b/xmodule/modulestore/tests/django_utils.py @@ -318,7 +318,7 @@ class ModuleStoreIsolationMixin(CacheIsolationMixin, SignalIsolationMixin): cls.__old_modulestores.append(copy.deepcopy(settings.MODULESTORE)) cls.__old_contentstores.append(copy.deepcopy(settings.CONTENTSTORE)) - override.__enter__() + override.__enter__() # pylint: disable=unnecessary-dunder-call cls.__settings_overrides.append(override) XMODULE_FACTORY_LOCK.enable() clear_existing_modulestores() diff --git a/xmodule/tests/__init__.py b/xmodule/tests/__init__.py index 4554d2e19f..107d6b27bc 100644 --- a/xmodule/tests/__init__.py +++ b/xmodule/tests/__init__.py @@ -465,9 +465,9 @@ class CourseComparisonTest(TestCase): actual_course_key, None, sort=('displayname', ModuleStoreEnum.SortOrder.descending) ) assert len(expected_course_assets) == len(actual_course_assets) - for idx, __ in enumerate(expected_course_assets): + for idx, expected_val in enumerate(expected_course_assets): for attr in AssetMetadata.ATTRS_ALLOWED_TO_UPDATE: if attr in ('edited_on',): # edited_on is updated upon import. continue - assert getattr(expected_course_assets[idx], attr) == getattr(actual_course_assets[idx], attr) + assert getattr(expected_val, attr) == getattr(actual_course_assets[idx], attr) diff --git a/xmodule/x_module.py b/xmodule/x_module.py index 3dc3190d2d..65cf099208 100644 --- a/xmodule/x_module.py +++ b/xmodule/x_module.py @@ -86,9 +86,11 @@ DEFAULT_PUBLIC_VIEW_MESSAGE = ( 'Sign in or register, and enroll in this course to view it.' ) + # Make '_' a no-op so we can scrape strings. Using lambda instead of # `django.utils.translation.ugettext_noop` because Django cannot be imported in this file -_ = lambda text: text +def _(text): + return text class OpaqueKeyReader(IdReader): @@ -1800,7 +1802,7 @@ class CombinedSystem: """ context = context or {} - return self.__getattr__('render')(block, view_name, context) + return self.__getattr__('render')(block, view_name, context) # pylint: disable=unnecessary-dunder-call def service(self, block, service_name): """Return a service, or None.