style: code cleanups from Steven Burch (#29292)

* chore: update deprecated import from collections

* chore: remove outdated imports from markdown library

as it hasn't been supported since 2.0.3 and we're on 3.x.
This was deprecated at least as early as 2012!

* docs: add docstring and remove lint-amnesty to markdown plugin

* chore: remove deprecated etree import

* style: remove unnecessary-comprehension for sets

* style: resolve a number of amnestied pylint complaints

Co-authored-by: stvn <stvn@mit.edu>
This commit is contained in:
Ned Batchelder
2021-11-10 07:11:57 -08:00
committed by GitHub
parent 1d2319b42a
commit d9dd10dc97
30 changed files with 71 additions and 88 deletions

View File

@@ -223,7 +223,7 @@ def mock_registered_transformers(transformers):
'openedx.core.djangoapps.content.block_structure.transformer_registry.'
'TransformerRegistry.get_registered_transformers'
) as mock_available_transforms:
mock_available_transforms.return_value = {transformer for transformer in transformers} # lint-amnesty, pylint: disable=unnecessary-comprehension
mock_available_transforms.return_value = set(transformers)
yield

View File

@@ -191,7 +191,7 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase
if the library allows direct learning.
"""
databases = {alias for alias in connections} # lint-amnesty, pylint: disable=unnecessary-comprehension
databases = set(connections)
@XBlock.register_temp_plugin(UserStateTestBlock, UserStateTestBlock.BLOCK_TYPE)
def test_default_values(self):

View File

@@ -307,7 +307,7 @@ class AccountLegacyProfileSerializer(serializers.HyperlinkedModelSerializer, Rea
"""
Enforce all languages are unique.
"""
language_proficiencies = [language for language in value] # lint-amnesty, pylint: disable=unnecessary-comprehension
language_proficiencies = list(value)
unique_language_proficiencies = {language["code"] for language in language_proficiencies}
if len(language_proficiencies) != len(unique_language_proficiencies):
raise serializers.ValidationError("The language_proficiencies field must consist of unique languages.")
@@ -317,7 +317,7 @@ class AccountLegacyProfileSerializer(serializers.HyperlinkedModelSerializer, Rea
"""
Enforce only one entry for a particular social platform.
"""
social_links = [social_link for social_link in value] # lint-amnesty, pylint: disable=unnecessary-comprehension
social_links = list(value)
unique_social_links = {social_link["platform"] for social_link in social_links}
if len(social_links) != len(unique_social_links):
raise serializers.ValidationError("The social_links field must consist of unique social platforms.")

View File

@@ -152,10 +152,10 @@ class RetirementTestCase(TestCase):
return [create_retirement_status(UserFactory(), state=state) for state in RetirementState.objects.all()]
def _get_non_dead_end_states(self):
return [state for state in RetirementState.objects.filter(is_dead_end_state=False)] # lint-amnesty, pylint: disable=unnecessary-comprehension
return RetirementState.objects.filter(is_dead_end_state=False)
def _get_dead_end_states(self):
return [state for state in RetirementState.objects.filter(is_dead_end_state=True)] # lint-amnesty, pylint: disable=unnecessary-comprehension
return RetirementState.objects.filter(is_dead_end_state=True)
def fake_requested_retirement(user):

View File

@@ -401,7 +401,7 @@ class EmailOptInListTest(ModuleStoreTestCase):
try:
with open(output_path) as output_file:
reader = csv.DictReader(output_file, fieldnames=self.OUTPUT_FIELD_NAMES)
rows = [row for row in reader] # lint-amnesty, pylint: disable=unnecessary-comprehension
rows = list(reader)
except OSError:
self.fail(f"Could not find or open output file at '{output_path}'")

View File

@@ -2501,11 +2501,11 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase, OpenEdxEventsTestM
)
@ddt.data(
['name', [name for name in testutils.VALID_NAMES]], # lint-amnesty, pylint: disable=unnecessary-comprehension
['email', [email for email in testutils.VALID_EMAILS]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['password', [password for password in testutils.VALID_PASSWORDS]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['username', [username for username in testutils.VALID_USERNAMES]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['country', [country for country in testutils.VALID_COUNTRIES]] # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['name', list(testutils.VALID_NAMES)],
['email', list(testutils.VALID_EMAILS)],
['password', list(testutils.VALID_PASSWORDS)],
['username', list(testutils.VALID_USERNAMES)],
['country', list(testutils.VALID_COUNTRIES)],
)
@ddt.unpack
def test_positive_validation_decision(self, form_field_name, user_data):
@@ -2519,11 +2519,11 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase, OpenEdxEventsTestM
@ddt.data(
# Skip None type for invalidity checks.
['name', [name for name in testutils.INVALID_NAMES[1:]]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['email', [email for email in testutils.INVALID_EMAILS[1:]]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['password', [password for password in testutils.INVALID_PASSWORDS[1:]]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['username', [username for username in testutils.INVALID_USERNAMES[1:]]], # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['country', [country for country in testutils.INVALID_COUNTRIES[1:]]] # lint-amnesty, pylint: disable=unnecessary-comprehension, line-too-long
['name', testutils.INVALID_NAMES[1:]],
['email', testutils.INVALID_EMAILS[1:]],
['password', testutils.INVALID_PASSWORDS[1:]],
['username', testutils.INVALID_USERNAMES[1:]],
['country', testutils.INVALID_COUNTRIES[1:]],
)
@ddt.unpack
def test_negative_validation_decision(self, form_field_name, user_data):

View File

@@ -2,7 +2,7 @@
Utilities related to API views
"""
from collections import Sequence # lint-amnesty, pylint: disable=no-name-in-module, deprecated-class
from collections.abc import Sequence
from functools import wraps
from django.core.exceptions import NON_FIELD_ERRORS, ObjectDoesNotExist, ValidationError