From 4f4be6538ae008a6d65cd7cc49d776aebfa9e40a Mon Sep 17 00:00:00 2001 From: Usama Sadiq <usama.sadiq@arbisoft.com> Date: Tue, 11 May 2021 17:22:40 +0500 Subject: [PATCH] BOM-2477: pylint warnings lint-amnesty (#27585) --- .../management/commands/import_content_library.py | 2 +- cms/djangoapps/contentstore/tasks.py | 4 ++-- .../contentstore/tests/test_transcripts_utils.py | 2 +- .../contentstore/views/tests/test_import_export.py | 2 +- .../contentstore/views/tests/test_transcripts.py | 2 +- common/djangoapps/edxmako/shortcuts.py | 1 - .../student/management/commands/assigngroups.py | 2 +- common/djangoapps/student/models.py | 3 +-- common/djangoapps/terrain/stubs/tests/test_lti_stub.py | 6 +++--- common/djangoapps/track/contexts.py | 2 +- common/djangoapps/track/middleware.py | 2 +- common/djangoapps/track/tracker.py | 2 +- common/djangoapps/track/transformers.py | 2 +- common/lib/capa/capa/responsetypes.py | 2 +- common/lib/capa/capa/tests/test_responsetypes.py | 2 +- common/lib/symmath/symmath/formula.py | 2 +- common/lib/xmodule/xmodule/modulestore/search.py | 2 +- .../lib/xmodule/xmodule/modulestore/tests/factories.py | 2 +- common/lib/xmodule/xmodule/progress.py | 4 ++-- common/test/acceptance/fixtures/course.py | 2 +- lms/djangoapps/commerce/api/v0/tests/test_views.py | 2 +- lms/djangoapps/commerce/api/v0/views.py | 2 +- .../course_home_api/course_metadata/v1/views.py | 2 +- lms/djangoapps/courseware/tests/test_video_handlers.py | 4 ++-- lms/djangoapps/discussion/rest_api/views.py | 4 ++-- .../grades/rest_api/v1/tests/test_gradebook_views.py | 2 +- .../instructor_task/tests/test_tasks_helper.py | 2 +- openedx/core/djangoapps/courseware_api/views.py | 2 +- .../management/commands/notify_credentials.py | 2 +- .../commands/tests/test_notify_credentials.py | 2 +- .../core/djangoapps/credentials/tests/test_signals.py | 4 ++-- openedx/core/djangoapps/discussions/views.py | 2 +- .../core/djangoapps/profile_images/tests/helpers.py | 2 +- openedx/core/djangoapps/programs/tests/test_utils.py | 2 +- .../management/tests/test_email_opt_in_list.py | 2 +- openedx/core/djangoapps/user_authn/utils.py | 2 +- openedx/core/djangoapps/user_authn/views/login.py | 2 +- openedx/core/lib/html_to_text.py | 2 +- openedx/core/process_warnings.py | 2 +- openedx/core/pytest_hooks.py | 2 +- openedx/core/write_to_html.py | 2 +- .../course_experience/tests/views/test_course_dates.py | 2 +- openedx/features/course_experience/url_helpers.py | 2 +- .../features/course_experience/views/course_home.py | 2 +- .../features/course_experience/views/course_updates.py | 2 +- .../course_experience/views/welcome_message.py | 2 +- openedx/features/enterprise_support/signals.py | 2 +- pavelib/paver_tests/test_paver_quality.py | 6 +++--- pavelib/prereqs.py | 6 +++--- pavelib/utils/process.py | 10 +++++----- pavelib/utils/test/suites/suite.py | 2 +- scripts/thresholds.sh | 4 ++-- 52 files changed, 67 insertions(+), 69 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/import_content_library.py b/cms/djangoapps/contentstore/management/commands/import_content_library.py index 56e1eaa2b8f..9d33523cdb5 100644 --- a/cms/djangoapps/contentstore/management/commands/import_content_library.py +++ b/cms/djangoapps/contentstore/management/commands/import_content_library.py @@ -47,7 +47,7 @@ class Command(BaseCommand): course_dir = data_root / subdir # Extract library archive - tar_file = tarfile.open(archive_path) + tar_file = tarfile.open(archive_path) # lint-amnesty, pylint: disable=consider-using-with try: safetar_extractall(tar_file, course_dir.encode('utf-8')) except SuspiciousOperation as exc: diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 21b8b02f9bc..c19fd75c359 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -336,7 +336,7 @@ def create_export_tarball(course_module, course_key, context, status=None): Updates the context with any error information if applicable. """ name = course_module.url_name - export_file = NamedTemporaryFile(prefix=name + '.', suffix=".tar.gz") + export_file = NamedTemporaryFile(prefix=name + '.', suffix=".tar.gz") # lint-amnesty, pylint: disable=consider-using-with root_dir = path(mkdtemp()) try: @@ -595,7 +595,7 @@ def import_olx(self, user_id, course_key_string, archive_path, archive_name, lan # try-finally block for proper clean up after receiving file. try: - tar_file = tarfile.open(temp_filepath) + tar_file = tarfile.open(temp_filepath) # lint-amnesty, pylint: disable=consider-using-with try: safetar_extractall(tar_file, (course_dir + '/')) except SuspiciousOperation as exc: diff --git a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py index 57dcf3d93eb..d4d82776326 100644 --- a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py +++ b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py @@ -812,7 +812,7 @@ class TestGetTranscript(SharedModuleStoreTestCase): """ Create srt file. """ - srt_file = tempfile.NamedTemporaryFile(suffix=".srt") + srt_file = tempfile.NamedTemporaryFile(suffix=".srt") # lint-amnesty, pylint: disable=consider-using-with srt_file.content_type = transcripts_utils.Transcript.SRT srt_file.write(content) srt_file.seek(0) diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index aec9190c828..ed1df9665c7 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -720,7 +720,7 @@ class ExportTestCase(CourseTestCase): resp_content += item buff = BytesIO(resp_content) - return tarfile.open(fileobj=buff) + return tarfile.open(fileobj=buff) # lint-amnesty, pylint: disable=consider-using-with def _verify_export_succeeded(self, resp): """ Export success helper method. """ diff --git a/cms/djangoapps/contentstore/views/tests/test_transcripts.py b/cms/djangoapps/contentstore/views/tests/test_transcripts.py index dd99f170f1d..644dcc7250f 100644 --- a/cms/djangoapps/contentstore/views/tests/test_transcripts.py +++ b/cms/djangoapps/contentstore/views/tests/test_transcripts.py @@ -183,7 +183,7 @@ class TestUploadTranscripts(BaseTranscripts): """ Setup a transcript file with suffix and content. """ - transcript_file = tempfile.NamedTemporaryFile(suffix=suffix) + transcript_file = tempfile.NamedTemporaryFile(suffix=suffix) # lint-amnesty, pylint: disable=consider-using-with wrapped_content = textwrap.dedent(content) if include_bom: wrapped_content = wrapped_content.encode('utf-8-sig') diff --git a/common/djangoapps/edxmako/shortcuts.py b/common/djangoapps/edxmako/shortcuts.py index 012db3f6535..2a9d8849cb3 100644 --- a/common/djangoapps/edxmako/shortcuts.py +++ b/common/djangoapps/edxmako/shortcuts.py @@ -15,7 +15,6 @@ import logging -import six from django.conf import settings from django.http import HttpResponse # lint-amnesty, pylint: disable=unused-import from django.template import engines diff --git a/common/djangoapps/student/management/commands/assigngroups.py b/common/djangoapps/student/management/commands/assigngroups.py index 77b76a1f93f..52833974569 100644 --- a/common/djangoapps/student/management/commands/assigngroups.py +++ b/common/djangoapps/student/management/commands/assigngroups.py @@ -68,7 +68,7 @@ class Command(BaseCommand): # lint-amnesty, pylint: disable=missing-class-docst group_objects = {} - f = open(options['log_name'], "a+") + f = open(options['log_name'], "a+") # lint-amnesty, pylint: disable=consider-using-with # Create groups for group in dict(groups): diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index fa5d7fc47a6..b0546f14cac 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -3218,8 +3218,7 @@ class UserCelebration(TimeStampedModel): if last_day_of_streak != self.last_day_of_streak: self.last_day_of_streak = last_day_of_streak self.streak_length = streak_length - if self.longest_ever_streak < streak_length: - self.longest_ever_streak = streak_length + self.longest_ever_streak = max(self.longest_ever_streak, streak_length) self.save() diff --git a/common/djangoapps/terrain/stubs/tests/test_lti_stub.py b/common/djangoapps/terrain/stubs/tests/test_lti_stub.py index bf8e4d8c6a3..1d04f47cd9d 100644 --- a/common/djangoapps/terrain/stubs/tests/test_lti_stub.py +++ b/common/djangoapps/terrain/stubs/tests/test_lti_stub.py @@ -74,7 +74,7 @@ class StubLtiServiceTest(unittest.TestCase): grade_uri = self.uri + 'grade' with patch('common.djangoapps.terrain.stubs.lti.requests.post') as mocked_post: mocked_post.return_value = Mock(content='Test response', status_code=200) - response = urlopen(grade_uri, data=b'') + response = urlopen(grade_uri, data=b'') # lint-amnesty, pylint: disable=consider-using-with assert b'Test response' in response.read() @patch('common.djangoapps.terrain.stubs.lti.signature.verify_hmac_sha1', return_value=True) @@ -84,7 +84,7 @@ class StubLtiServiceTest(unittest.TestCase): grade_uri = self.uri + 'lti2_outcome' with patch('common.djangoapps.terrain.stubs.lti.requests.put') as mocked_put: mocked_put.return_value = Mock(status_code=200) - response = urlopen(grade_uri, data=b'') + response = urlopen(grade_uri, data=b'') # lint-amnesty, pylint: disable=consider-using-with assert b'LTI consumer (edX) responded with HTTP 200' in response.read() @patch('common.djangoapps.terrain.stubs.lti.signature.verify_hmac_sha1', return_value=True) @@ -94,5 +94,5 @@ class StubLtiServiceTest(unittest.TestCase): grade_uri = self.uri + 'lti2_delete' with patch('common.djangoapps.terrain.stubs.lti.requests.put') as mocked_put: mocked_put.return_value = Mock(status_code=200) - response = urlopen(grade_uri, data=b'') + response = urlopen(grade_uri, data=b'') # lint-amnesty, pylint: disable=consider-using-with assert b'LTI consumer (edX) responded with HTTP 200' in response.read() diff --git a/common/djangoapps/track/contexts.py b/common/djangoapps/track/contexts.py index c4b09ebf93e..6d4e9da3caf 100644 --- a/common/djangoapps/track/contexts.py +++ b/common/djangoapps/track/contexts.py @@ -5,7 +5,7 @@ import logging from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, LearningContextKey -from six import text_type +from six import text_type # lint-amnesty, pylint: disable=unused-import from openedx.core.lib.request_utils import COURSE_REGEX diff --git a/common/djangoapps/track/middleware.py b/common/djangoapps/track/middleware.py index 01b1b0a771f..e3c384632a1 100644 --- a/common/djangoapps/track/middleware.py +++ b/common/djangoapps/track/middleware.py @@ -12,7 +12,7 @@ import logging import re import sys -import six +import six # lint-amnesty, pylint: disable=unused-import from django.conf import settings from django.utils.deprecation import MiddlewareMixin from eventtracking import tracker diff --git a/common/djangoapps/track/tracker.py b/common/djangoapps/track/tracker.py index 9f8c7f00fc0..53ae9f23874 100644 --- a/common/djangoapps/track/tracker.py +++ b/common/djangoapps/track/tracker.py @@ -24,7 +24,7 @@ import inspect import warnings from importlib import import_module -import six +import six # lint-amnesty, pylint: disable=unused-import from django.conf import settings from common.djangoapps.track.backends import BaseBackend diff --git a/common/djangoapps/track/transformers.py b/common/djangoapps/track/transformers.py index 595b5028cc7..aa4a3d17a65 100644 --- a/common/djangoapps/track/transformers.py +++ b/common/djangoapps/track/transformers.py @@ -9,7 +9,7 @@ apply them to the appropriate events. import json import logging -import six +import six # lint-amnesty, pylint: disable=unused-import from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import UsageKey diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 085c6f13cba..107311800d4 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -2777,7 +2777,7 @@ class CodeResponse(LoncapaResponse): # matches if oldcmap.is_right_queuekey(self.answer_id, queuekey): # Sanity check on returned points - if points < 0: + if points < 0: # lint-amnesty, pylint: disable=consider-using-max-builtin points = 0 # Queuestate is consumed oldcmap.set( diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index bf1f9dcf31b..6ed360f8a22 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -2304,7 +2304,7 @@ class CustomResponseTest(ResponseTest): # pylint: disable=missing-class-docstri # Make a zipfile with one module in it with one function. zipstring = io.BytesIO() - zipf = zipfile.ZipFile(zipstring, "w") + zipf = zipfile.ZipFile(zipstring, "w") # lint-amnesty, pylint: disable=consider-using-with zipf.writestr("my_helper.py", textwrap.dedent("""\ def seventeen(): return 17 diff --git a/common/lib/symmath/symmath/formula.py b/common/lib/symmath/symmath/formula.py index 126be0b6257..715e981218f 100644 --- a/common/lib/symmath/symmath/formula.py +++ b/common/lib/symmath/symmath/formula.py @@ -21,7 +21,7 @@ import unicodedata from copy import deepcopy from functools import reduce -import six +import six # lint-amnesty, pylint: disable=unused-import import sympy from lxml import etree from sympy import latex, sympify diff --git a/common/lib/xmodule/xmodule/modulestore/search.py b/common/lib/xmodule/xmodule/modulestore/search.py index d1e7762a671..674a5a3169c 100644 --- a/common/lib/xmodule/xmodule/modulestore/search.py +++ b/common/lib/xmodule/xmodule/modulestore/search.py @@ -6,7 +6,7 @@ from logging import getLogger from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.masquerade import MASQUERADE_SETTINGS_KEY -from common.djangoapps.student.roles import GlobalStaff +from common.djangoapps.student.roles import GlobalStaff # lint-amnesty, pylint: disable=unused-import from .exceptions import ItemNotFoundError, NoPathToItem LOGGER = getLogger(__name__) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/factories.py b/common/lib/xmodule/xmodule/modulestore/tests/factories.py index 5aa7e067450..514abbced87 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/factories.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/factories.py @@ -324,7 +324,7 @@ class ItemFactory(XModuleFactory): return parent.location @classmethod - def _create(cls, target_class, **kwargs): # lint-amnesty, pylint: disable=arguments-differ, unused-argument + def _create(cls, target_class, **kwargs): # lint-amnesty, pylint: disable=arguments-differ, too-many-statements, unused-argument """ Uses ``**kwargs``: diff --git a/common/lib/xmodule/xmodule/progress.py b/common/lib/xmodule/xmodule/progress.py index 4c8c1bbcc9a..deaddd282b6 100644 --- a/common/lib/xmodule/xmodule/progress.py +++ b/common/lib/xmodule/xmodule/progress.py @@ -31,10 +31,10 @@ class Progress: # pylint: disable=eq-without-hash isinstance(b, numbers.Number)): raise TypeError(f'a and b must be numbers. Passed {a}/{b}') - if a > b: + if a > b: # lint-amnesty, pylint: disable=consider-using-min-builtin a = b - if a < 0: + if a < 0: # lint-amnesty, pylint: disable=consider-using-max-builtin a = 0 if b <= 0: diff --git a/common/test/acceptance/fixtures/course.py b/common/test/acceptance/fixtures/course.py index 23296c46f3e..2e43ff1a383 100644 --- a/common/test/acceptance/fixtures/course.py +++ b/common/test/acceptance/fixtures/course.py @@ -396,7 +396,7 @@ class CourseFixture(XBlockContainerFixture): for asset_name in self._assets: asset_file_path = test_dir + '/data/uploads/' + asset_name - asset_file = open(asset_file_path, mode='rb') # lint-amnesty, pylint: disable=bad-option-value, open-builtin + asset_file = open(asset_file_path, mode='rb') # lint-amnesty, pylint: disable=consider-using-with files = {'file': (asset_name, asset_file, mimetypes.guess_type(asset_file_path)[0])} headers = { diff --git a/lms/djangoapps/commerce/api/v0/tests/test_views.py b/lms/djangoapps/commerce/api/v0/tests/test_views.py index dfcadd03b33..5a1e47cb714 100644 --- a/lms/djangoapps/commerce/api/v0/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v0/tests/test_views.py @@ -17,7 +17,7 @@ from django.urls import reverse, reverse_lazy from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory from common.djangoapps.student.models import CourseEnrollment -from common.djangoapps.student.tests.tests import EnrollmentEventTestMixin +from common.djangoapps.student.tests.tests import EnrollmentEventTestMixin # lint-amnesty, pylint: disable=unused-import from openedx.core.djangoapps.embargo.test_utils import restrict_course from openedx.core.djangoapps.enrollments.api import get_enrollment from openedx.core.lib.django_test_client_utils import get_absolute_url diff --git a/lms/djangoapps/commerce/api/v0/views.py b/lms/djangoapps/commerce/api/v0/views.py index a8fd9313de3..26dafe0343e 100644 --- a/lms/djangoapps/commerce/api/v0/views.py +++ b/lms/djangoapps/commerce/api/v0/views.py @@ -150,7 +150,7 @@ class BasketsView(APIView): ) log.info(msg) self._enroll(course_key, user, default_enrollment_mode.slug) - mode = CourseMode.AUDIT if audit_mode else CourseMode.HONOR + mode = CourseMode.AUDIT if audit_mode else CourseMode.HONOR # lint-amnesty, pylint: disable=unused-variable self._handle_marketing_opt_in(request, course_key, user) return DetailResponse(msg) else: diff --git a/lms/djangoapps/course_home_api/course_metadata/v1/views.py b/lms/djangoapps/course_home_api/course_metadata/v1/views.py index 78a323d810f..4417f3d44ae 100644 --- a/lms/djangoapps/course_home_api/course_metadata/v1/views.py +++ b/lms/djangoapps/course_home_api/course_metadata/v1/views.py @@ -14,7 +14,7 @@ from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiv from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict from openedx.core.djangoapps.courseware_api.views import CoursewareMeta -from common.djangoapps.student.models import CourseEnrollment, UserCelebration +from common.djangoapps.student.models import CourseEnrollment, UserCelebration # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.course_api.api import course_detail from lms.djangoapps.course_home_api.course_metadata.v1.serializers import CourseHomeMetadataSerializer from lms.djangoapps.courseware.access import has_access diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 9f944f0a3a0..0d266f5e8f6 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -49,7 +49,7 @@ def _create_srt_file(content=None): """ content = content or SRT_content - srt_file = tempfile.NamedTemporaryFile(suffix=".srt") + srt_file = tempfile.NamedTemporaryFile(suffix=".srt") # lint-amnesty, pylint: disable=consider-using-with srt_file.content_type = 'application/x-subrip; charset=utf-8' srt_file.write(content.encode('utf-8')) srt_file.seek(0) @@ -93,7 +93,7 @@ def _create_file(content=''): """ Create temporary subs_somevalue.srt.sjson file. """ - sjson_file = tempfile.NamedTemporaryFile(prefix="subs_", suffix=".srt.sjson") + sjson_file = tempfile.NamedTemporaryFile(prefix="subs_", suffix=".srt.sjson") # lint-amnesty, pylint: disable=consider-using-with sjson_file.content_type = 'application/json' sjson_file.write(textwrap.dedent(content).encode('utf-8')) sjson_file.seek(0) diff --git a/lms/djangoapps/discussion/rest_api/views.py b/lms/djangoapps/discussion/rest_api/views.py index b18ddbb7c12..418df91bf1d 100644 --- a/lms/djangoapps/discussion/rest_api/views.py +++ b/lms/djangoapps/discussion/rest_api/views.py @@ -16,7 +16,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.viewsets import ViewSet -from lms.djangoapps.discussion.django_comment_client.utils import available_division_schemes +from lms.djangoapps.discussion.django_comment_client.utils import available_division_schemes # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.discussion.rest_api.api import ( create_comment, create_thread, @@ -43,7 +43,7 @@ from lms.djangoapps.discussion.rest_api.serializers import ( DiscussionRolesSerializer, DiscussionSettingsSerializer ) -from lms.djangoapps.discussion.views import get_divided_discussions +from lms.djangoapps.discussion.views import get_divided_discussions # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.instructor.access import update_forum_role from openedx.core.djangoapps.django_comment_common import comment_client from openedx.core.djangoapps.django_comment_common.models import Role diff --git a/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py b/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py index 0bc48d31a79..b0141f14aef 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py @@ -1043,7 +1043,7 @@ class GradebookViewTest(GradebookViewTestBase): assert status.HTTP_200_OK == resp.status_code actual_data = dict(resp.data) expected_page_size = page_size or CourseEnrollmentPagination.page_size - if expected_page_size > user_size: + if expected_page_size > user_size: # lint-amnesty, pylint: disable=consider-using-min-builtin expected_page_size = user_size assert len(actual_data['results']) == expected_page_size diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index 742a8461dad..ce8cfabc3b5 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -1423,7 +1423,7 @@ class MockDefaultStorage: def open(self, file_name): """Mock out DefaultStorage.open with standard python open""" - return open(file_name) # lint-amnesty, pylint: disable=bad-option-value, open-builtin + return open(file_name) # lint-amnesty, pylint: disable=bad-option-value, open-builtin # lint-amnesty, pylint: disable=consider-using-with @patch('lms.djangoapps.instructor_task.tasks_helper.misc.DefaultStorage', new=MockDefaultStorage) diff --git a/openedx/core/djangoapps/courseware_api/views.py b/openedx/core/djangoapps/courseware_api/views.py index d29f2c99033..01052b9edea 100644 --- a/openedx/core/djangoapps/courseware_api/views.py +++ b/openedx/core/djangoapps/courseware_api/views.py @@ -2,7 +2,7 @@ Course API Views """ -import json +import json # lint-amnesty, pylint: disable=unused-import from completion.exceptions import UnavailableCompletionData from completion.utilities import get_key_to_last_completed_block diff --git a/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py b/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py index 840403420df..92472b92887 100644 --- a/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py +++ b/openedx/core/djangoapps/credentials/management/commands/notify_credentials.py @@ -13,7 +13,7 @@ signals.) import logging import shlex -import sys +import sys # lint-amnesty, pylint: disable=unused-import from datetime import datetime, timedelta import dateutil.parser diff --git a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py index be70f413f8e..059c7819754 100644 --- a/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py +++ b/openedx/core/djangoapps/credentials/management/commands/tests/test_notify_credentials.py @@ -8,7 +8,7 @@ from unittest import mock from django.core.management import call_command from django.core.management.base import CommandError -from django.test import TestCase, override_settings +from django.test import TestCase, override_settings # lint-amnesty, pylint: disable=unused-import from freezegun import freeze_time from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory, CourseFactory, CourseRunFactory diff --git a/openedx/core/djangoapps/credentials/tests/test_signals.py b/openedx/core/djangoapps/credentials/tests/test_signals.py index c73625803d6..5ea44fafa00 100644 --- a/openedx/core/djangoapps/credentials/tests/test_signals.py +++ b/openedx/core/djangoapps/credentials/tests/test_signals.py @@ -3,8 +3,8 @@ from unittest import mock -from django.conf import settings -from django.test import TestCase, override_settings +from django.conf import settings # lint-amnesty, pylint: disable=unused-import +from django.test import TestCase, override_settings # lint-amnesty, pylint: disable=unused-import from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory diff --git a/openedx/core/djangoapps/discussions/views.py b/openedx/core/djangoapps/discussions/views.py index a3ff3a374f2..18a7ae9a1ea 100644 --- a/openedx/core/djangoapps/discussions/views.py +++ b/openedx/core/djangoapps/discussions/views.py @@ -126,7 +126,7 @@ class LegacySettingsSerializer(serializers.BaseSerializer): raise serializers.ValidationError('Wrong type for discussion_topics') payload = { key: value - for key, value in data.items() + for key, value in data.items() # lint-amnesty, pylint: disable=unnecessary-comprehension } return payload diff --git a/openedx/core/djangoapps/profile_images/tests/helpers.py b/openedx/core/djangoapps/profile_images/tests/helpers.py index 3170b58234f..cbb6e76ac95 100644 --- a/openedx/core/djangoapps/profile_images/tests/helpers.py +++ b/openedx/core/djangoapps/profile_images/tests/helpers.py @@ -28,7 +28,7 @@ def make_image_file(dimensions=(320, 240), prefix='tmp', extension='.jpeg', forc """ image = Image.new('RGB', dimensions, "green") - image_file = NamedTemporaryFile(prefix=prefix, suffix=extension) + image_file = NamedTemporaryFile(prefix=prefix, suffix=extension) # lint-amnesty, pylint: disable=consider-using-with try: if orientation and orientation in range(1, 9): exif_bytes = piexif.dump({'0th': {piexif.ImageIFD.Orientation: orientation}}) diff --git a/openedx/core/djangoapps/programs/tests/test_utils.py b/openedx/core/djangoapps/programs/tests/test_utils.py index 68db25827bf..b61fdfe5ea0 100644 --- a/openedx/core/djangoapps/programs/tests/test_utils.py +++ b/openedx/core/djangoapps/programs/tests/test_utils.py @@ -475,7 +475,7 @@ class TestProgramProgressMeter(ModuleStoreTestCase): programs = data[:3] assert meter.engaged_programs == programs - def test_simulate_progress(self, mock_get_programs): + def test_simulate_progress(self, mock_get_programs): # lint-amnesty, pylint: disable=too-many-statements """Simulate the entirety of a user's progress through a program.""" today = datetime.datetime.now(utc) two_days_ago = today - datetime.timedelta(days=2) diff --git a/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py b/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py index e167fb5a466..0a1a5121ae5 100644 --- a/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py +++ b/openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py @@ -274,7 +274,7 @@ class EmailOptInListTest(ModuleStoreTestCase): call_command('email_opt_in_list', *args) def test_file_already_exists(self): - temp_file = tempfile.NamedTemporaryFile(delete=True) + temp_file = tempfile.NamedTemporaryFile(delete=True) # lint-amnesty, pylint: disable=consider-using-with def _cleanup(): temp_file.close() diff --git a/openedx/core/djangoapps/user_authn/utils.py b/openedx/core/djangoapps/user_authn/utils.py index e6635a23cab..8947cd9d98f 100644 --- a/openedx/core/djangoapps/user_authn/utils.py +++ b/openedx/core/djangoapps/user_authn/utils.py @@ -5,7 +5,7 @@ Utility functions used during user authentication. import random import string from urllib.parse import urlparse # pylint: disable=import-error -from uuid import uuid4 +from uuid import uuid4 # lint-amnesty, pylint: disable=unused-import from django.conf import settings from django.utils import http diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index 58c349bfacb..0900d5c28ec 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -44,7 +44,7 @@ from openedx.core.djangoapps.user_authn.views.utils import ( from openedx.core.djangoapps.user_authn.toggles import is_require_third_party_auth_enabled from openedx.core.djangoapps.user_authn.config.waffle import ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY from openedx.core.djangolib.markup import HTML, Text -from openedx.core.lib.api.view_utils import require_post_params +from openedx.core.lib.api.view_utils import require_post_params # lint-amnesty, pylint: disable=unused-import from openedx.features.enterprise_support.api import activate_learner_enterprise, get_enterprise_learner_data_from_api from common.djangoapps.student.helpers import get_next_url_for_login_page, get_redirect_url_with_host from common.djangoapps.student.models import LoginFailures, AllowedAuthUser, UserProfile diff --git a/openedx/core/lib/html_to_text.py b/openedx/core/lib/html_to_text.py index a6d2daddf78..fdb851840ca 100644 --- a/openedx/core/lib/html_to_text.py +++ b/openedx/core/lib/html_to_text.py @@ -12,7 +12,7 @@ def html_to_text(html_message): Currently uses lynx in a subprocess; should be refactored to use something more pythonic. """ - process = Popen( + process = Popen( # lint-amnesty, pylint: disable=consider-using-with ['lynx', '-stdin', '-display_charset=UTF-8', '-assume_charset=UTF-8', '-dump'], stdin=PIPE, stdout=PIPE diff --git a/openedx/core/process_warnings.py b/openedx/core/process_warnings.py index 331816d196e..6141fc874dc 100644 --- a/openedx/core/process_warnings.py +++ b/openedx/core/process_warnings.py @@ -4,7 +4,7 @@ Script to process pytest warnings output by pytest-json-report plugin and output """ import argparse -import io +import io # lint-amnesty, pylint: disable=unused-import import itertools import json import os diff --git a/openedx/core/pytest_hooks.py b/openedx/core/pytest_hooks.py index 1552b394961..49911c92f87 100644 --- a/openedx/core/pytest_hooks.py +++ b/openedx/core/pytest_hooks.py @@ -2,7 +2,7 @@ Module to put all pytest hooks that modify pytest behaviour """ import os -import io +import io # lint-amnesty, pylint: disable=unused-import import json diff --git a/openedx/core/write_to_html.py b/openedx/core/write_to_html.py index aa35b8a575a..8c211e11382 100644 --- a/openedx/core/write_to_html.py +++ b/openedx/core/write_to_html.py @@ -2,7 +2,7 @@ Class used to write pytest warning data into html format """ import textwrap -import six +import six # lint-amnesty, pylint: disable=unused-import class HtmlOutlineWriter: diff --git a/openedx/features/course_experience/tests/views/test_course_dates.py b/openedx/features/course_experience/tests/views/test_course_dates.py index 19d5ef8f0aa..af7867741c4 100644 --- a/openedx/features/course_experience/tests/views/test_course_dates.py +++ b/openedx/features/course_experience/tests/views/test_course_dates.py @@ -5,7 +5,7 @@ Tests for course dates fragment. from datetime import datetime, timedelta -import six +import six # lint-amnesty, pylint: disable=unused-import from django.urls import reverse from common.djangoapps.student.tests.factories import UserFactory diff --git a/openedx/features/course_experience/url_helpers.py b/openedx/features/course_experience/url_helpers.py index 122e9ab7f59..c0ab5f62624 100644 --- a/openedx/features/course_experience/url_helpers.py +++ b/openedx/features/course_experience/url_helpers.py @@ -7,7 +7,7 @@ because the Studio course outline may need these utilities. from enum import Enum from typing import Optional -import six +import six # lint-amnesty, pylint: disable=unused-import from django.conf import settings from django.contrib.auth import get_user_model from django.http import HttpRequest diff --git a/openedx/features/course_experience/views/course_home.py b/openedx/features/course_experience/views/course_home.py index 89f12028eaf..3718c4e8b4e 100644 --- a/openedx/features/course_experience/views/course_home.py +++ b/openedx/features/course_experience/views/course_home.py @@ -3,7 +3,7 @@ Views for the course home page. """ -import six +import six # lint-amnesty, pylint: disable=unused-import from django.conf import settings from django.template.context_processors import csrf from django.template.loader import render_to_string diff --git a/openedx/features/course_experience/views/course_updates.py b/openedx/features/course_experience/views/course_updates.py index 5f76b592ee2..f3ee5de4ad9 100644 --- a/openedx/features/course_experience/views/course_updates.py +++ b/openedx/features/course_experience/views/course_updates.py @@ -2,7 +2,7 @@ Views that handle course updates. """ -import six +import six # lint-amnesty, pylint: disable=unused-import from django.contrib.auth.decorators import login_required from django.template.context_processors import csrf from django.template.loader import render_to_string diff --git a/openedx/features/course_experience/views/welcome_message.py b/openedx/features/course_experience/views/welcome_message.py index 19f64a68b97..410d3425a3e 100644 --- a/openedx/features/course_experience/views/welcome_message.py +++ b/openedx/features/course_experience/views/welcome_message.py @@ -3,7 +3,7 @@ View logic for handling course welcome messages. """ -import six +import six # lint-amnesty, pylint: disable=unused-import from django.http import HttpResponse from django.template.loader import render_to_string from django.urls import reverse diff --git a/openedx/features/enterprise_support/signals.py b/openedx/features/enterprise_support/signals.py index 316df2702b4..84d321c9851 100644 --- a/openedx/features/enterprise_support/signals.py +++ b/openedx/features/enterprise_support/signals.py @@ -9,7 +9,7 @@ from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.db.models.signals import post_save, pre_save from django.dispatch import receiver -from enterprise.models import EnterpriseCourseEnrollment, EnterpriseCustomer, EnterpriseCustomerUser +from enterprise.models import EnterpriseCourseEnrollment, EnterpriseCustomer, EnterpriseCustomerUser # lint-amnesty, pylint: disable=unused-import from integrated_channels.integrated_channel.tasks import ( transmit_single_learner_data, transmit_single_subsection_learner_data diff --git a/pavelib/paver_tests/test_paver_quality.py b/pavelib/paver_tests/test_paver_quality.py index 5842c9dc0b7..62ba7580624 100644 --- a/pavelib/paver_tests/test_paver_quality.py +++ b/pavelib/paver_tests/test_paver_quality.py @@ -28,7 +28,7 @@ class TestPaverQualityViolations(unittest.TestCase): """ def setUp(self): super().setUp() - self.f = tempfile.NamedTemporaryFile(delete=False) + self.f = tempfile.NamedTemporaryFile(delete=False) # lint-amnesty, pylint: disable=consider-using-with self.f.close() self.addCleanup(os.remove, self.f.name) @@ -102,7 +102,7 @@ class TestPaverReportViolationsCounts(unittest.TestCase): super().setUp() # Temporary file infrastructure - self.f = tempfile.NamedTemporaryFile(delete=False) + self.f = tempfile.NamedTemporaryFile(delete=False) # lint-amnesty, pylint: disable=consider-using-with self.f.close() # Cleanup various mocks and tempfiles @@ -241,7 +241,7 @@ class TestPrepareReportDir(unittest.TestCase): def setUp(self): super().setUp() self.test_dir = tempfile.mkdtemp() - self.test_file = tempfile.NamedTemporaryFile(delete=False, dir=self.test_dir) + self.test_file = tempfile.NamedTemporaryFile(delete=False, dir=self.test_dir) # lint-amnesty, pylint: disable=consider-using-with self.addCleanup(os.removedirs, self.test_dir) def test_report_dir_with_files(self): diff --git a/pavelib/prereqs.py b/pavelib/prereqs.py index 9e7e8dcc34b..d56825cd990 100644 --- a/pavelib/prereqs.py +++ b/pavelib/prereqs.py @@ -135,20 +135,20 @@ def node_prereqs_installation(): npm_log_file_path = f'{Env.GEN_LOG_DIR}/npm-install.{shard_str}.log' else: npm_log_file_path = f'{Env.GEN_LOG_DIR}/npm-install.log' - npm_log_file = open(npm_log_file_path, 'wb') + npm_log_file = open(npm_log_file_path, 'wb') # lint-amnesty, pylint: disable=consider-using-with npm_command = 'npm install --verbose'.split() # The implementation of Paver's `sh` function returns before the forked # actually returns. Using a Popen object so that we can ensure that # the forked process has returned - proc = subprocess.Popen(npm_command, stderr=npm_log_file) + proc = subprocess.Popen(npm_command, stderr=npm_log_file) # lint-amnesty, pylint: disable=consider-using-with retcode = proc.wait() if retcode == 1: # Error handling around a race condition that produces "cb() never called" error. This # evinces itself as `cb_error_text` and it ought to disappear when we upgrade # npm to 3 or higher. TODO: clean this up when we do that. print("npm install error detected. Retrying...") - proc = subprocess.Popen(npm_command, stderr=npm_log_file) + proc = subprocess.Popen(npm_command, stderr=npm_log_file) # lint-amnesty, pylint: disable=consider-using-with retcode = proc.wait() if retcode == 1: raise Exception(f"npm install failed: See {npm_log_file_path}") diff --git a/pavelib/utils/process.py b/pavelib/utils/process.py index fd2ee5bfcf1..813c1b2c7c7 100644 --- a/pavelib/utils/process.py +++ b/pavelib/utils/process.py @@ -36,11 +36,11 @@ def run_multi_processes(cmd_list, out_log=None, err_log=None): pids = [] if out_log: - out_log_file = open(out_log, 'w') + out_log_file = open(out_log, 'w') # lint-amnesty, pylint: disable=consider-using-with kwargs['stdout'] = out_log_file if err_log: - err_log_file = open(err_log, 'w') + err_log_file = open(err_log, 'w') # lint-amnesty, pylint: disable=consider-using-with kwargs['stderr'] = err_log_file # If the user is performing a dry run of a task, then just log @@ -93,14 +93,14 @@ def run_background_process(cmd, out_log=None, err_log=None, cwd=None): kwargs = {'shell': True, 'cwd': cwd} if out_log: - out_log_file = open(out_log, 'w') + out_log_file = open(out_log, 'w') # lint-amnesty, pylint: disable=consider-using-with kwargs['stdout'] = out_log_file if err_log: - err_log_file = open(err_log, 'w') + err_log_file = open(err_log, 'w') # lint-amnesty, pylint: disable=consider-using-with kwargs['stderr'] = err_log_file - proc = subprocess.Popen(cmd, **kwargs) + proc = subprocess.Popen(cmd, **kwargs) # lint-amnesty, pylint: disable=consider-using-with def exit_handler(): """ diff --git a/pavelib/utils/test/suites/suite.py b/pavelib/utils/test/suites/suite.py index 9c7e96ce65a..5a423c827c2 100644 --- a/pavelib/utils/test/suites/suite.py +++ b/pavelib/utils/test/suites/suite.py @@ -99,7 +99,7 @@ class TestSuite: process = None try: - process = subprocess.Popen(cmd, **kwargs) + process = subprocess.Popen(cmd, **kwargs) # lint-amnesty, pylint: disable=consider-using-with return self.is_success(process.wait()) except KeyboardInterrupt: kill_process(process) diff --git a/scripts/thresholds.sh b/scripts/thresholds.sh index 26826157e98..ff982ed4311 100755 --- a/scripts/thresholds.sh +++ b/scripts/thresholds.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -export LOWER_PYLINT_THRESHOLD=200 -export UPPER_PYLINT_THRESHOLD=200 +export LOWER_PYLINT_THRESHOLD=0 +export UPPER_PYLINT_THRESHOLD=1 export ESLINT_THRESHOLD=5300 export STYLELINT_THRESHOLD=880 -- GitLab