From d37faa8270194713fe09c598c881b36adc0c3f38 Mon Sep 17 00:00:00 2001 From: Jawayria Date: Thu, 4 Feb 2021 15:18:10 +0500 Subject: [PATCH] BOM-2330: Applied pylint-amnesty to util, verified_track_content, video_config, video_pipeline --- openedx/core/djangoapps/util/apps.py | 2 +- openedx/core/djangoapps/util/forms.py | 6 +++--- .../util/management/commands/reset_db.py | 18 +++++++++--------- openedx/core/djangoapps/util/model_utils.py | 7 ++++--- openedx/core/djangoapps/util/ratelimit.py | 2 +- openedx/core/djangoapps/util/row_delete.py | 6 +++--- openedx/core/djangoapps/util/testing.py | 4 ++-- .../util/tests/test_print_setting.py | 6 +++--- .../util/tests/test_user_messages.py | 2 +- .../djangoapps/util/tests/test_user_utils.py | 2 +- openedx/core/djangoapps/util/user_messages.py | 18 +++++++++--------- .../djangoapps/verified_track_content/forms.py | 2 +- .../swap_from_auto_track_cohort_pilot.py | 14 +++++++------- .../djangoapps/verified_track_content/tasks.py | 2 +- .../tests/test_models.py | 2 +- .../core/djangoapps/video_config/__init__.py | 2 +- .../video_config/tests/test_models.py | 4 ++-- .../video_pipeline/tests/test_api.py | 2 +- .../video_pipeline/tests/test_models.py | 2 +- 19 files changed, 52 insertions(+), 51 deletions(-) diff --git a/openedx/core/djangoapps/util/apps.py b/openedx/core/djangoapps/util/apps.py index 51dac3287c..843082ea1a 100644 --- a/openedx/core/djangoapps/util/apps.py +++ b/openedx/core/djangoapps/util/apps.py @@ -18,4 +18,4 @@ class UtilConfig(AppConfig): """ Registers signal handlers at startup. """ - import openedx.core.djangoapps.util.signals # pylint: disable=unused-variable + import openedx.core.djangoapps.util.signals # lint-amnesty, pylint: disable=unused-import, unused-variable diff --git a/openedx/core/djangoapps/util/forms.py b/openedx/core/djangoapps/util/forms.py index a98bfdc514..fafeff8ea7 100644 --- a/openedx/core/djangoapps/util/forms.py +++ b/openedx/core/djangoapps/util/forms.py @@ -22,11 +22,11 @@ class MultiValueField(Field): """ widget = MultipleHiddenInput - def to_python(self, list_of_string_values): + def to_python(self, list_of_string_values): # lint-amnesty, pylint: disable=arguments-differ """ Convert the form input to a list of strings """ - values = super(MultiValueField, self).to_python(list_of_string_values) or set() + values = super(MultiValueField, self).to_python(list_of_string_values) or set() # lint-amnesty, pylint: disable=super-with-arguments if values: # combine all values if there were multiple specified individually @@ -37,7 +37,7 @@ class MultiValueField(Field): return values - def validate(self, values): + def validate(self, values): # lint-amnesty, pylint: disable=arguments-differ """ Ensure no empty values were passed """ diff --git a/openedx/core/djangoapps/util/management/commands/reset_db.py b/openedx/core/djangoapps/util/management/commands/reset_db.py index feea1cc7f2..30bacefb7a 100644 --- a/openedx/core/djangoapps/util/management/commands/reset_db.py +++ b/openedx/core/djangoapps/util/management/commands/reset_db.py @@ -22,7 +22,7 @@ from django.core.management.base import BaseCommand, CommandError from six.moves import configparser -class Command(BaseCommand): +class Command(BaseCommand): # lint-amnesty, pylint: disable=missing-class-docstring help = "Resets the database for this project." def add_arguments(self, parser): @@ -30,7 +30,7 @@ class Command(BaseCommand): '-R', '--router', action='store', dest='router', default='default', help='Use this router-database other than defined in settings.py') - def handle(self, *args, **options): + def handle(self, *args, **options): # lint-amnesty, pylint: disable=too-many-statements """ Resets the database for this project. @@ -87,16 +87,16 @@ class Command(BaseCommand): drop_query = u'DROP DATABASE IF EXISTS `%s`' % database_name utf8_support = 'CHARACTER SET utf8' create_query = u'CREATE DATABASE `%s` %s' % (database_name, utf8_support) - logging.info('Executing... "' + drop_query + '"') + logging.info('Executing... "' + drop_query + '"') # lint-amnesty, pylint: disable=logging-not-lazy connection.query(drop_query) - logging.info('Executing... "' + create_query + '"') + logging.info('Executing... "' + create_query + '"') # lint-amnesty, pylint: disable=logging-not-lazy connection.query(create_query) elif engine in ('postgresql', 'postgresql_psycopg2', 'postgis'): if engine == 'postgresql' and django.VERSION < (1, 9): - import psycopg as Database # NOQA + import psycopg as Database # NOQA # lint-amnesty, pylint: disable=import-error elif engine in ('postgresql', 'postgresql_psycopg2', 'postgis'): - import psycopg2 as Database # NOQA + import psycopg2 as Database # NOQA # lint-amnesty, pylint: disable=import-error conn_params = {'database': 'template1'} if user: @@ -113,7 +113,7 @@ class Command(BaseCommand): cursor = connection.cursor() drop_query = u"DROP DATABASE \"%s\";" % database_name - logging.info('Executing... "' + drop_query + '"') + logging.info('Executing... "' + drop_query + '"') # lint-amnesty, pylint: disable=logging-not-lazy try: cursor.execute(drop_query) except Database.ProgrammingError as e: @@ -127,7 +127,7 @@ class Command(BaseCommand): if engine == 'postgis' and django.VERSION < (1, 9): # For PostGIS 1.5, fetch template name if it exists from django.contrib.gis.db.backends.postgis.base import DatabaseWrapper - postgis_template = DatabaseWrapper(dbinfo).template_postgis + postgis_template = DatabaseWrapper(dbinfo).template_postgis # lint-amnesty, pylint: disable=no-member if postgis_template is not None: create_query += u' TEMPLATE = %s' % postgis_template @@ -136,7 +136,7 @@ class Command(BaseCommand): else: create_query += u';' - logging.info('Executing... "' + create_query + '"') + logging.info('Executing... "' + create_query + '"') # lint-amnesty, pylint: disable=logging-not-lazy cursor.execute(create_query) else: diff --git a/openedx/core/djangoapps/util/model_utils.py b/openedx/core/djangoapps/util/model_utils.py index 72ff3dc0e6..6c4156acc8 100644 --- a/openedx/core/djangoapps/util/model_utils.py +++ b/openedx/core/djangoapps/util/model_utils.py @@ -1,3 +1,4 @@ +# lint-amnesty, pylint: disable=missing-module-docstring class Creator(object): """ A placeholder class that provides a way to set the attribute on the model. @@ -5,7 +6,7 @@ class Creator(object): def __init__(self, field): self.field = field - def __get__(self, obj, type=None): + def __get__(self, obj, type=None): # lint-amnesty, pylint: disable=redefined-builtin if obj is None: return self return obj.__dict__[self.field.name] @@ -20,8 +21,8 @@ class CreatorMixin(object): See: https://docs.djangoproject.com/en/1.11/releases/1.8/#subfieldbase """ def contribute_to_class(self, cls, name, *args, **kwargs): - super(CreatorMixin, self).contribute_to_class(cls, name, *args, **kwargs) + super(CreatorMixin, self).contribute_to_class(cls, name, *args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments setattr(cls, name, Creator(self)) - def from_db_value(self, value, expression, connection): + def from_db_value(self, value, expression, connection): # lint-amnesty, pylint: disable=unused-argument return self.to_python(value) diff --git a/openedx/core/djangoapps/util/ratelimit.py b/openedx/core/djangoapps/util/ratelimit.py index 9639d6e618..d3ef9bf9f8 100644 --- a/openedx/core/djangoapps/util/ratelimit.py +++ b/openedx/core/djangoapps/util/ratelimit.py @@ -6,5 +6,5 @@ Code to get ip from request. from ipware.ip import get_ip -def real_ip(group, request): +def real_ip(group, request): # lint-amnesty, pylint: disable=unused-argument return get_ip(request) diff --git a/openedx/core/djangoapps/util/row_delete.py b/openedx/core/djangoapps/util/row_delete.py index 2cfe51bd75..1f8852c201 100644 --- a/openedx/core/djangoapps/util/row_delete.py +++ b/openedx/core/djangoapps/util/row_delete.py @@ -62,7 +62,7 @@ def delete_rows(model_mgr, # The "as id" below fools Django raw query into thinking the primary key is being queried. # It's necessary because Django will throw an exception if the raw SQL does not query the primary key. min_max_ids = model_mgr.raw( - u'SELECT MIN({}) as id, MAX({}) as max_id FROM {}'.format(primary_id_name, primary_id_name, table_name) + u'SELECT MIN({}) as id, MAX({}) as max_id FROM {}'.format(primary_id_name, primary_id_name, table_name) # lint-amnesty, pylint: disable=duplicate-string-formatting-argument )[0] min_id = min_max_ids.id max_id = min_max_ids.max_id @@ -81,7 +81,7 @@ def delete_rows(model_mgr, log.info(u"Deleting around %s rows between ids %s and %s...", deletions_now, lower_id, upper_id) with transaction.atomic(): # xss-lint: disable=python-wrap-html - delete_sql = u'DELETE FROM {} WHERE {} >= {} AND {} < {}'.format( + delete_sql = u'DELETE FROM {} WHERE {} >= {} AND {} < {}'.format( # lint-amnesty, pylint: disable=duplicate-string-formatting-argument table_name, primary_id_name, lower_id, primary_id_name, upper_id ) log.info(delete_sql) @@ -113,7 +113,7 @@ class BaseDeletionCommand(BaseCommand): '--chunk_size', default=self.DEFAULT_CHUNK_SIZE, type=int, - help='Maximum number of rows to delete in each DB transaction. Choose this value carefully to avoid DB outages!' + help='Maximum number of rows to delete in each DB transaction. Choose this value carefully to avoid DB outages!' # lint-amnesty, pylint: disable=line-too-long ) parser.add_argument( '--sleep_between', diff --git a/openedx/core/djangoapps/util/testing.py b/openedx/core/djangoapps/util/testing.py index 3ab1637c02..8da1181359 100644 --- a/openedx/core/djangoapps/util/testing.py +++ b/openedx/core/djangoapps/util/testing.py @@ -25,7 +25,7 @@ class ContentGroupTestCase(ModuleStoreTestCase): and a non-cohorted user with no special access. """ def setUp(self): - super(ContentGroupTestCase, self).setUp() + super(ContentGroupTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = CourseFactory.create( org='org', number='number', run='run', @@ -144,7 +144,7 @@ class TestConditionalContent(ModuleStoreTestCase): -> vertical (Group B) -> problem """ - super(TestConditionalContent, self).setUp() + super(TestConditionalContent, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Create user partitions self.user_partition_group_a = 0 diff --git a/openedx/core/djangoapps/util/tests/test_print_setting.py b/openedx/core/djangoapps/util/tests/test_print_setting.py index f7a3fc683c..b9c964484d 100644 --- a/openedx/core/djangoapps/util/tests/test_print_setting.py +++ b/openedx/core/djangoapps/util/tests/test_print_setting.py @@ -1,11 +1,11 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # lint-amnesty, pylint: disable=missing-module-docstring import pytest from django.core.management import CommandError, call_command -def test_without_args(capsys): +def test_without_args(capsys): # lint-amnesty, pylint: disable=unused-argument with pytest.raises(CommandError, match='Error: the following arguments are required: setting'): call_command('print_setting') @@ -13,6 +13,6 @@ def test_without_args(capsys): def test_with_setting_args(capsys): call_command('print_setting', 'DEBUG') - out, err = capsys.readouterr() + out, err = capsys.readouterr() # lint-amnesty, pylint: disable=unused-variable assert 'False' in out assert 'INSTALLED_APPS' not in out diff --git a/openedx/core/djangoapps/util/tests/test_user_messages.py b/openedx/core/djangoapps/util/tests/test_user_messages.py index ffb2240fee..d8b81a4916 100644 --- a/openedx/core/djangoapps/util/tests/test_user_messages.py +++ b/openedx/core/djangoapps/util/tests/test_user_messages.py @@ -22,7 +22,7 @@ class UserMessagesTestCase(TestCase): Unit tests for page level user messages. """ def setUp(self): - super(UserMessagesTestCase, self).setUp() + super(UserMessagesTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.student = UserFactory.create() self.request = RequestFactory().request() self.request.session = {} diff --git a/openedx/core/djangoapps/util/tests/test_user_utils.py b/openedx/core/djangoapps/util/tests/test_user_utils.py index 3abe7041ee..093e7d4c85 100644 --- a/openedx/core/djangoapps/util/tests/test_user_utils.py +++ b/openedx/core/djangoapps/util/tests/test_user_utils.py @@ -12,7 +12,7 @@ from ..user_utils import SystemUser class SystemUserTestCase(unittest.TestCase): """ Tests for response-related utility functions """ def setUp(self): - super(SystemUserTestCase, self).setUp() + super(SystemUserTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.sysuser = SystemUser() def test_system_user_is_anonymous(self): diff --git a/openedx/core/djangoapps/util/user_messages.py b/openedx/core/djangoapps/util/user_messages.py index a40f031a93..84ad806dba 100644 --- a/openedx/core/djangoapps/util/user_messages.py +++ b/openedx/core/djangoapps/util/user_messages.py @@ -54,7 +54,7 @@ class UserMessage(): """ Representation of a message to be shown to a user. """ - def __init__(self, type, message_html): + def __init__(self, type, message_html): # lint-amnesty, pylint: disable=redefined-builtin assert isinstance(type, UserMessageType) self.type = type self.message_html = message_html @@ -80,7 +80,7 @@ class UserMessageCollection(): """ @classmethod @abstractmethod - def get_namespace(self): + def get_namespace(self): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Returns the namespace of the message collection. @@ -125,35 +125,35 @@ class UserMessageCollection(): messages.add_message(request, message_type.value, Text(message), extra_tags=cls.get_namespace()) @classmethod - def register_info_message(self, request, message, **kwargs): + def register_info_message(self, request, message, **kwargs): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Registers an information message to be shown to the user. """ self.register_user_message(request, UserMessageType.INFO, message, **kwargs) @classmethod - def register_success_message(self, request, message, **kwargs): + def register_success_message(self, request, message, **kwargs): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Registers a success message to be shown to the user. """ self.register_user_message(request, UserMessageType.SUCCESS, message, **kwargs) @classmethod - def register_warning_message(self, request, message, **kwargs): + def register_warning_message(self, request, message, **kwargs): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Registers a warning message to be shown to the user. """ self.register_user_message(request, UserMessageType.WARNING, message, **kwargs) @classmethod - def register_error_message(self, request, message, **kwargs): + def register_error_message(self, request, message, **kwargs): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Registers an error message to be shown to the user. """ self.register_user_message(request, UserMessageType.ERROR, message, **kwargs) @classmethod - def user_messages(self, request): + def user_messages(self, request): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Returns any outstanding user messages. @@ -164,7 +164,7 @@ class UserMessageCollection(): """ Returns the user message type associated with a level. """ - for __, type in UserMessageType.__members__.items(): + for __, type in UserMessageType.__members__.items(): # lint-amnesty, pylint: disable=redefined-builtin if type.value is level: return type raise Exception(u'Unable to find UserMessageType for level {level}'.format(level=level)) @@ -222,7 +222,7 @@ class PageLevelMessages(UserMessageCollection): ) @classmethod - def get_namespace(self): + def get_namespace(self): # lint-amnesty, pylint: disable=bad-classmethod-argument """ Returns the namespace of the message collection. """ diff --git a/openedx/core/djangoapps/verified_track_content/forms.py b/openedx/core/djangoapps/verified_track_content/forms.py index 4c342e0739..4a4834e894 100644 --- a/openedx/core/djangoapps/verified_track_content/forms.py +++ b/openedx/core/djangoapps/verified_track_content/forms.py @@ -46,7 +46,7 @@ class VerifiedTrackCourseForm(forms.ModelForm): try: course_key = CourseKey.from_string(cleaned_id) except InvalidKeyError: - raise forms.ValidationError(error_msg) + raise forms.ValidationError(error_msg) # lint-amnesty, pylint: disable=raise-missing-from if not modulestore().has_course(course_key): raise forms.ValidationError(error_msg) diff --git a/openedx/core/djangoapps/verified_track_content/management/commands/swap_from_auto_track_cohort_pilot.py b/openedx/core/djangoapps/verified_track_content/management/commands/swap_from_auto_track_cohort_pilot.py index 26dfb7cd57..3e7bee968e 100644 --- a/openedx/core/djangoapps/verified_track_content/management/commands/swap_from_auto_track_cohort_pilot.py +++ b/openedx/core/djangoapps/verified_track_content/management/commands/swap_from_auto_track_cohort_pilot.py @@ -26,7 +26,7 @@ class Command(BaseCommand): """ help = dedent(__doc__).strip() - def handle(self, *args, **options): + def handle(self, *args, **options): # lint-amnesty, pylint: disable=too-many-statements errors = [] @@ -103,7 +103,7 @@ class Command(BaseCommand): try: verified_track_cohorted_course = VerifiedTrackCohortedCourse.objects.get(course_key=old_course_key) except VerifiedTrackCohortedCourse.DoesNotExist: - raise CommandError(u"No VerifiedTrackCohortedCourse found for course: '%s'" % old_course_key) + raise CommandError(u"No VerifiedTrackCohortedCourse found for course: '%s'" % old_course_key) # lint-amnesty, pylint: disable=raise-missing-from if not verified_track_cohorted_course.enabled: raise CommandError(u"VerifiedTrackCohortedCourse not enabled for course: '%s'" % old_course_key) @@ -117,7 +117,7 @@ class Command(BaseCommand): name=verified_track_cohorted_course.verified_cohort_name ) except CourseUserGroup.DoesNotExist: - raise CommandError( + raise CommandError( # lint-amnesty, pylint: disable=raise-missing-from u"No Verified CourseUserGroup found for course_id='%s' with group_type='%s' for names='%s'" % (old_course_key, CourseUserGroup.COHORT, verified_track_cohorted_course.verified_cohort_name) ) @@ -127,7 +127,7 @@ class Command(BaseCommand): course_user_group_id=verified_course_user_group.id ) except CourseUserGroupPartitionGroup.DoesNotExist: - raise CommandError( + raise CommandError( # lint-amnesty, pylint: disable=raise-missing-from u"No Verified CourseUserGroupPartitionGroup found for course_user_group_ids='%s'" % random_audit_course_user_group_ids ) @@ -139,7 +139,7 @@ class Command(BaseCommand): mode_slug=CourseMode.AUDIT ) except CourseMode.DoesNotExist: - raise CommandError(u"Audit CourseMode is not defined for course: '%s'" % rerun_course_key) + raise CommandError(u"Audit CourseMode is not defined for course: '%s'" % rerun_course_key) # lint-amnesty, pylint: disable=raise-missing-from try: CourseMode.objects.get( @@ -147,7 +147,7 @@ class Command(BaseCommand): mode_slug=CourseMode.VERIFIED ) except CourseMode.DoesNotExist: - raise CommandError(u"Verified CourseMode is not defined for course: '%s'" % rerun_course_key) + raise CommandError(u"Verified CourseMode is not defined for course: '%s'" % rerun_course_key) # lint-amnesty, pylint: disable=raise-missing-from items = module_store.get_items(rerun_course_key) if not items: @@ -233,7 +233,7 @@ class Command(BaseCommand): # Check if we should delete any partition groups if there are no errors. # If there are errors, none of the xblock items will have been updated, # so this section will throw errors for each partition in use - if partitions_to_delete and not errors: + if partitions_to_delete and not errors: # lint-amnesty, pylint: disable=too-many-nested-blocks partition_service = PartitionService(rerun_course_key) course = partition_service.get_course() for partition_to_delete in partitions_to_delete: diff --git a/openedx/core/djangoapps/verified_track_content/tasks.py b/openedx/core/djangoapps/verified_track_content/tasks.py index b4a9082c67..b40f530b97 100644 --- a/openedx/core/djangoapps/verified_track_content/tasks.py +++ b/openedx/core/djangoapps/verified_track_content/tasks.py @@ -7,7 +7,7 @@ import six from celery.task import task from celery.utils.log import get_task_logger -from django.contrib.auth.models import User +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey diff --git a/openedx/core/djangoapps/verified_track_content/tests/test_models.py b/openedx/core/djangoapps/verified_track_content/tests/test_models.py index 8a500bb2b6..af73a80231 100644 --- a/openedx/core/djangoapps/verified_track_content/tests/test_models.py +++ b/openedx/core/djangoapps/verified_track_content/tests/test_models.py @@ -81,7 +81,7 @@ class TestMoveToVerified(SharedModuleStoreTestCase): cls.course = CourseFactory.create() def setUp(self): - super(TestMoveToVerified, self).setUp() + super(TestMoveToVerified, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory() # Spy on number of calls to celery task. celery_task_patcher = mock.patch.object( diff --git a/openedx/core/djangoapps/video_config/__init__.py b/openedx/core/djangoapps/video_config/__init__.py index c1188dde9b..ae448c0a86 100644 --- a/openedx/core/djangoapps/video_config/__init__.py +++ b/openedx/core/djangoapps/video_config/__init__.py @@ -1 +1 @@ -# TODO Move this Application to video codebase when Video XModule becomes an XBlock. Reference: TNL-6867. +# TODO Move this Application to video codebase when Video XModule becomes an XBlock. Reference: TNL-6867. # lint-amnesty, pylint: disable=django-not-configured diff --git a/openedx/core/djangoapps/video_config/tests/test_models.py b/openedx/core/djangoapps/video_config/tests/test_models.py index fb63d0afad..ac6345162d 100644 --- a/openedx/core/djangoapps/video_config/tests/test_models.py +++ b/openedx/core/djangoapps/video_config/tests/test_models.py @@ -3,9 +3,9 @@ Tests for the models that configures HLS Playback feature. """ import ddt -import itertools +import itertools # lint-amnesty, pylint: disable=wrong-import-order -from contextlib import contextmanager +from contextlib import contextmanager # lint-amnesty, pylint: disable=wrong-import-order from django.test import TestCase diff --git a/openedx/core/djangoapps/video_pipeline/tests/test_api.py b/openedx/core/djangoapps/video_pipeline/tests/test_api.py index 2f025f7816..dd3c585551 100644 --- a/openedx/core/djangoapps/video_pipeline/tests/test_api.py +++ b/openedx/core/djangoapps/video_pipeline/tests/test_api.py @@ -19,7 +19,7 @@ class TestAPIUtils(VideoPipelineMixin, TestCase): """ Tests for API Utils. """ - def setUp(self): + def setUp(self): # lint-amnesty, pylint: disable=super-method-not-called """ Setup VEM oauth client. """ diff --git a/openedx/core/djangoapps/video_pipeline/tests/test_models.py b/openedx/core/djangoapps/video_pipeline/tests/test_models.py index 313c78e97a..7120b75ba3 100644 --- a/openedx/core/djangoapps/video_pipeline/tests/test_models.py +++ b/openedx/core/djangoapps/video_pipeline/tests/test_models.py @@ -3,7 +3,7 @@ Tests for the models that configures 'VideoUploadsEnabledByDefault' feature. """ import ddt -import itertools +import itertools # lint-amnesty, pylint: disable=wrong-import-order from django.test import TestCase from openedx.core.djangoapps.video_config.tests.test_models import FeatureFlagTestMixin