From 484cd536e25ca74b4354c6b61c52084d8b935bf2 Mon Sep 17 00:00:00 2001 From: Usama Sadiq Date: Thu, 23 Sep 2021 17:54:04 +0500 Subject: [PATCH] fix: Fixed new pylint warnings (#28724) --- cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py | 2 +- cms/djangoapps/contentstore/tests/test_course_settings.py | 2 +- common/djangoapps/student/helpers.py | 2 +- common/djangoapps/student/models.py | 2 +- common/djangoapps/terrain/stubs/edxnotes.py | 4 ++-- common/djangoapps/terrain/stubs/http.py | 4 ++-- common/djangoapps/terrain/stubs/start.py | 2 +- common/djangoapps/terrain/stubs/youtube.py | 2 +- .../djangoapps/third_party_auth/api/tests/test_permissions.py | 2 +- common/djangoapps/track/transformers.py | 4 ++-- .../djangoapps/util/tests/test_password_policy_validators.py | 2 +- openedx/core/djangoapps/bookmarks/tests/factories.py | 2 +- openedx/core/djangoapps/catalog/utils.py | 2 +- .../djangoapps/content/learning_sequences/api/outlines.py | 2 +- openedx/core/djangoapps/embargo/views.py | 2 +- openedx/core/djangoapps/theming/helpers.py | 2 +- openedx/core/djangoapps/util/row_delete.py | 2 +- openedx/features/lti_course_tab/tab.py | 2 +- pavelib/assets.py | 4 ++-- pavelib/i18n.py | 2 +- pavelib/utils/envs.py | 4 ++-- 21 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py index 9502952803..c8d7419af2 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py @@ -229,7 +229,7 @@ class TabsAPITests(CourseTestCase): @ddt.data( dict(is_hidden=None), dict(is_hidden="abc"), - dict(), + {}, ) def test_toggle_tab_invalid_visibility(self, invalid_visibility): """ diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index efed2e20a4..a85592b9ca 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -718,7 +718,7 @@ class CourseGradingTest(CourseTestCase): 'event_transaction_id': 'mockUUID', 'event_transaction_type': 'edx.grades.grading_policy_changed', } - ) for policy_hash in {grading_policy_2, grading_policy_3} + ) for policy_hash in [grading_policy_2, grading_policy_3] ], any_order=True) @mock.patch('common.djangoapps.track.event_transaction_utils.uuid4') diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index 14f01bbc5e..625311d070 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -341,7 +341,7 @@ def _get_redirect_to(request_host, request_headers, request_params, request_is_h header_accept = request_headers.get('HTTP_ACCEPT', '') accepts_text_html = any( mime_type in header_accept - for mime_type in {'*/*', 'text/*', 'text/html'} + for mime_type in ['*/*', 'text/*', 'text/html'] ) # If we get a redirect parameter, make sure it's safe i.e. not redirecting outside our domain. diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 4dbd1995d8..1f98d2f6df 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -656,7 +656,7 @@ class UserProfile(models.Model): def get_meta(self): # pylint: disable=missing-function-docstring js_str = self.meta if not js_str: - js_str = dict() + js_str = {} else: js_str = json.loads(self.meta) diff --git a/common/djangoapps/terrain/stubs/edxnotes.py b/common/djangoapps/terrain/stubs/edxnotes.py index 3e40a26c5d..a147825c25 100644 --- a/common/djangoapps/terrain/stubs/edxnotes.py +++ b/common/djangoapps/terrain/stubs/edxnotes.py @@ -300,7 +300,7 @@ class StubEdxNotesService(StubHttpService): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.notes = list() + self.notes = [] def get_all_notes(self): """ @@ -348,7 +348,7 @@ class StubEdxNotesService(StubHttpService): """ Removes all notes to the stub EdxNotes service. """ - self.notes = list() + self.notes = [] def filter_by_id(self, data, note_id): """ diff --git a/common/djangoapps/terrain/stubs/http.py b/common/djangoapps/terrain/stubs/http.py index 96373d542b..a0730b594d 100644 --- a/common/djangoapps/terrain/stubs/http.py +++ b/common/djangoapps/terrain/stubs/http.py @@ -118,7 +118,7 @@ class StubHttpRequestHandler(BaseHTTPRequestHandler): } except: # lint-amnesty, pylint: disable=bare-except - return dict() + return {} @lazy def get_params(self): @@ -252,7 +252,7 @@ class StubHttpService(ThreadingMixIn, HTTPServer): HTTPServer.__init__(self, address, self.HANDLER_CLASS) # Create a dict to store configuration values set by the client - self.config = dict() + self.config = {} # Start the server in a separate thread server_thread = threading.Thread(target=self.serve_forever) diff --git a/common/djangoapps/terrain/stubs/start.py b/common/djangoapps/terrain/stubs/start.py index 1da87da935..976fb058f9 100644 --- a/common/djangoapps/terrain/stubs/start.py +++ b/common/djangoapps/terrain/stubs/start.py @@ -71,7 +71,7 @@ def _parse_config_args(args): Returns a dictionary with the configuration keys and values. """ - config_dict = dict() + config_dict = {} for config_str in args: try: components = config_str.split('=') diff --git a/common/djangoapps/terrain/stubs/youtube.py b/common/djangoapps/terrain/stubs/youtube.py index f120761027..e054d87420 100644 --- a/common/djangoapps/terrain/stubs/youtube.py +++ b/common/djangoapps/terrain/stubs/youtube.py @@ -41,7 +41,7 @@ class StubYouTubeHandler(StubHttpRequestHandler): Allow callers to delete all the server configurations using the /del_config URL. """ if self.path == "/del_config" or self.path == "/del_config/": - self.server.config = dict() + self.server.config = {} self.log_message("Reset Server Configuration.") self.send_response(200) else: diff --git a/common/djangoapps/third_party_auth/api/tests/test_permissions.py b/common/djangoapps/third_party_auth/api/tests/test_permissions.py index 386e455108..0820f9db8e 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_permissions.py +++ b/common/djangoapps/third_party_auth/api/tests/test_permissions.py @@ -40,7 +40,7 @@ class ThirdPartyAuthPermissionTest(TestCase): def _create_request(self, auth_header=None): url = '/' - extra = dict(HTTP_AUTHORIZATION=auth_header) if auth_header else dict() + extra = dict(HTTP_AUTHORIZATION=auth_header) if auth_header else {} return RequestFactory().get(url, **extra) def _create_session(self, request, user): diff --git a/common/djangoapps/track/transformers.py b/common/djangoapps/track/transformers.py index aa4a3d17a6..8ff9a86f4f 100644 --- a/common/djangoapps/track/transformers.py +++ b/common/djangoapps/track/transformers.py @@ -219,7 +219,7 @@ class EventTransformer(dict): def load_payload(self): """ - Create a data version of self[u'event'] at self.event + Create a data version of self['event'] at self.event """ if 'event' in self: if isinstance(self['event'], str): @@ -229,7 +229,7 @@ class EventTransformer(dict): def dump_payload(self): """ - Write self.event back to self[u'event']. + Write self.event back to self['event']. Keep the same format we were originally given. """ diff --git a/common/djangoapps/util/tests/test_password_policy_validators.py b/common/djangoapps/util/tests/test_password_policy_validators.py index e316049379..f0ffe3c2b1 100644 --- a/common/djangoapps/util/tests/test_password_policy_validators.py +++ b/common/djangoapps/util/tests/test_password_policy_validators.py @@ -68,7 +68,7 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase): assert len(not_normalized_password) == 3 # When we normalize we expect the not_normalized password to fail - # because it should be normalized to u'\u1E69' -> ṩ + # because it should be normalized to '\u1E69' -> ṩ self.validation_errors_checker(not_normalized_password, 'This password is too short. It must contain at least 2 characters.') diff --git a/openedx/core/djangoapps/bookmarks/tests/factories.py b/openedx/core/djangoapps/bookmarks/tests/factories.py index 444a1ca686..43934dec00 100644 --- a/openedx/core/djangoapps/bookmarks/tests/factories.py +++ b/openedx/core/djangoapps/bookmarks/tests/factories.py @@ -42,4 +42,4 @@ class XBlockCacheFactory(DjangoModelFactory): course_key = COURSE_KEY usage_key = factory.Sequence('4x://edx/100/block/{}'.format) display_name = '' - paths = list() + paths = [] diff --git a/openedx/core/djangoapps/catalog/utils.py b/openedx/core/djangoapps/catalog/utils.py index 4eb1e79b70..6362ed202c 100644 --- a/openedx/core/djangoapps/catalog/utils.py +++ b/openedx/core/djangoapps/catalog/utils.py @@ -593,7 +593,7 @@ def get_course_run_details(course_run_key, fields): Returns: dict with language, start date, end date, and max_effort details about specified course run """ - course_run_details = dict() + course_run_details = {} user, catalog_integration = check_catalog_integration_and_get_user( error_message_field=f'Data for course_run {course_run_key}' ) diff --git a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py index 218fd7d504..d0260da22c 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py @@ -348,7 +348,7 @@ def _get_user_course_outline_and_processors(course_key: CourseKey, # lint-amnes # Run each OutlineProcessor in order to figure out what items we have to # remove from the CourseOutline. - processors = dict() + processors = {} usage_keys_to_remove = set() inaccessible_sequences = set() for name, processor_cls in processor_classes: diff --git a/openedx/core/djangoapps/embargo/views.py b/openedx/core/djangoapps/embargo/views.py index 12e0361b21..e801d1b129 100644 --- a/openedx/core/djangoapps/embargo/views.py +++ b/openedx/core/djangoapps/embargo/views.py @@ -101,7 +101,7 @@ class CourseAccessMessageView(View): embargo.messages.BlockedMessage or None """ - message_dict = dict() + message_dict = {} # The access point determines which set of messages to use. # This allows us to show different messages to students who diff --git a/openedx/core/djangoapps/theming/helpers.py b/openedx/core/djangoapps/theming/helpers.py index 0e1da2a4ae..7b6745846e 100644 --- a/openedx/core/djangoapps/theming/helpers.py +++ b/openedx/core/djangoapps/theming/helpers.py @@ -89,7 +89,7 @@ def get_all_theme_template_dirs(): (list): list of directories containing theme templates. """ themes = get_themes() - template_paths = list() + template_paths = [] for theme in themes: template_paths.extend(theme.template_dirs) diff --git a/openedx/core/djangoapps/util/row_delete.py b/openedx/core/djangoapps/util/row_delete.py index 16f9e632d2..a0ecc240b2 100644 --- a/openedx/core/djangoapps/util/row_delete.py +++ b/openedx/core/djangoapps/util/row_delete.py @@ -88,7 +88,7 @@ def delete_rows(model_mgr, try: list(model_mgr.raw(delete_sql)) except TypeError: - # The list() above is simply to get the RawQuerySet to be evaluated. + # The [] above is simply to get the RawQuerySet to be evaluated. # Without evaluation, the raw DELETE SQL will *not* actually execute. # But - it will cause a "TypeError: 'NoneType' object is not iterable" to be ignored. pass diff --git a/openedx/features/lti_course_tab/tab.py b/openedx/features/lti_course_tab/tab.py index b5bce357eb..0c15b57772 100644 --- a/openedx/features/lti_course_tab/tab.py +++ b/openedx/features/lti_course_tab/tab.py @@ -209,7 +209,7 @@ class LtiCourseTab(LtiCourseLaunchMixin, EnrolledTab): self.lti_config_id = tab_dict.get('lti_config_id') if tab_dict else lti_config_id if tab_dict is None: - tab_dict = dict() + tab_dict = {} if name is not None: tab_dict['name'] = name diff --git a/pavelib/assets.py b/pavelib/assets.py index 073d60f79a..0f96b69779 100644 --- a/pavelib/assets.py +++ b/pavelib/assets.py @@ -114,7 +114,7 @@ def get_sass_directories(system, theme_dir=None): ) system = SYSTEMS[system] - applicable_directories = list() + applicable_directories = [] if theme_dir: # Add theme sass directories @@ -141,7 +141,7 @@ def get_common_sass_directories(): "lookup_paths": [], # list of directories to be passed as lookup paths for @import resolution. } """ - applicable_directories = list() + applicable_directories = [] # add common sass directories applicable_directories.append({ diff --git a/pavelib/i18n.py b/pavelib/i18n.py index 6c11ff7158..713d935de5 100644 --- a/pavelib/i18n.py +++ b/pavelib/i18n.py @@ -135,7 +135,7 @@ def i18n_validate_transifex_config(): home = path('~').expanduser() config = home / '.transifexrc' - if not config.isfile or config.getsize == 0: + if not config.isfile or config.getsize == 0: # pylint: disable=comparison-with-callable msg = colorize( 'red', "Cannot connect to Transifex, config file is missing" diff --git a/pavelib/utils/envs.py b/pavelib/utils/envs.py index 152160b5ab..98f5abec40 100644 --- a/pavelib/utils/envs.py +++ b/pavelib/utils/envs.py @@ -331,7 +331,7 @@ class Env: "at '{path}'".format(path=env_path), file=sys.stderr, ) - return dict() + return {} # Otherwise, load the file as JSON and return the resulting dict try: @@ -351,7 +351,7 @@ class Env: """ Return a dictionary of feature flags configured by the environment. """ - return self.env_tokens.get('FEATURES', dict()) + return self.env_tokens.get('FEATURES', {}) @classmethod def rsync_dirs(cls):