From 9a128034676300f5483d421994a08d6c7f96665c Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Thu, 10 Oct 2024 15:46:57 +0200 Subject: [PATCH] Enable ruff's N (pep8 naming) set of rules --- lms/db/_locks.py | 2 +- lms/models/exceptions.py | 2 +- lms/services/application_instance.py | 6 +++--- lms/services/blackboard_api/_schemas.py | 8 ++++---- lms/services/exceptions.py | 4 ++-- lms/services/jstor/service.py | 2 +- lms/services/organization.py | 4 ++-- lms/services/user.py | 2 +- lms/services/vitalsource/_client.py | 2 +- lms/services/vitalsource/exceptions.py | 2 +- lms/services/youtube.py | 2 +- lms/views/api/sync.py | 2 +- pyproject.toml | 1 + 13 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lms/db/_locks.py b/lms/db/_locks.py index c36a184b8f..5fa972e5e4 100644 --- a/lms/db/_locks.py +++ b/lms/db/_locks.py @@ -4,7 +4,7 @@ from sqlalchemy.orm import Session -class CouldNotAcquireLock(Exception): +class CouldNotAcquireLock(Exception): # noqa: N818 """A lock could not be immediately acquired.""" diff --git a/lms/models/exceptions.py b/lms/models/exceptions.py index e4db251abb..6ee09a372c 100644 --- a/lms/models/exceptions.py +++ b/lms/models/exceptions.py @@ -1,4 +1,4 @@ -class ReusedConsumerKey(Exception): +class ReusedConsumerKey(Exception): # noqa: N818 """Application Instance launched in a different LMS install.""" def __init__(self, existing_guid, new_guid): diff --git a/lms/services/application_instance.py b/lms/services/application_instance.py index 62f1700396..a72766bc90 100644 --- a/lms/services/application_instance.py +++ b/lms/services/application_instance.py @@ -16,11 +16,11 @@ LOG = getLogger(__name__) -class ApplicationInstanceNotFound(Exception): +class ApplicationInstanceNotFound(Exception): # noqa: N818 """The requested ApplicationInstance wasn't found in the database.""" -class AccountDisabled(SerializableError): +class AccountDisabled(SerializableError): # noqa: N818 """Indicate that we have disabled this account through it's org.""" def __init__(self, application_instance: ApplicationInstance): @@ -34,7 +34,7 @@ def __init__(self, application_instance: ApplicationInstance): ) -class ProvisioningDisabled(SerializableError): +class ProvisioningDisabled(SerializableError): # noqa: N818 """ Indicate that provisioning is not enabled for this instance. diff --git a/lms/services/blackboard_api/_schemas.py b/lms/services/blackboard_api/_schemas.py index e8e6c407fd..1e83a2a5e8 100644 --- a/lms/services/blackboard_api/_schemas.py +++ b/lms/services/blackboard_api/_schemas.py @@ -23,9 +23,9 @@ class Meta: name = fields.Str(required=True) modified = fields.Str(required=True) type = fields.Str(required=True) - mimeType = fields.Str() + mimeType = fields.Str() # noqa: N815 size = fields.Integer() - parentId = fields.Str() + parentId = fields.Str() # noqa: N815 results = fields.List(fields.Nested(FileSchema), required=True) @@ -37,7 +37,7 @@ def post_load(self, data, **_kwargs): class BlackboardPublicURLSchema(RequestsResponseSchema): """Schema for Blackboard /courses/{courseId}/resources/{resourceId} responses.""" - downloadUrl = fields.Str(required=True) + downloadUrl = fields.Str(required=True) # noqa: N815 @post_load def post_load(self, data, **_kwargs): @@ -74,7 +74,7 @@ class Meta: id = fields.Str(required=True) name = fields.Str(required=True) - groupSetId = fields.Str(required=False, allow_none=True) + groupSetId = fields.Str(required=False, allow_none=True) # noqa: N815 enrollment = fields.Nested(EnrollmentSchema, required=True) results = fields.List(fields.Nested(GroupSchema), required=True) diff --git a/lms/services/exceptions.py b/lms/services/exceptions.py index 260dd4162d..7d4df1310d 100644 --- a/lms/services/exceptions.py +++ b/lms/services/exceptions.py @@ -278,14 +278,14 @@ def __init__( self.details = details -class FileNotFoundInCourse(SerializableError): +class FileNotFoundInCourse(SerializableError): # noqa: N818 """A file wasn't found in the current course.""" def __init__(self, error_code: str, document_id): super().__init__(error_code=error_code, details={"document_id": document_id}) -class StudentNotInCourse(SerializableError): +class StudentNotInCourse(SerializableError): # noqa: N818 """A student is no longer in the current course.""" def __init__(self, grading_id): diff --git a/lms/services/jstor/service.py b/lms/services/jstor/service.py index 5df9063e97..c6d3991f81 100644 --- a/lms/services/jstor/service.py +++ b/lms/services/jstor/service.py @@ -10,7 +10,7 @@ from lms.views.helpers import via_url -class ArticleNotFound(SerializableError): +class ArticleNotFound(SerializableError): # noqa: N818 def __init__(self, article_id): super().__init__(message=f"Article '{article_id}' not found") diff --git a/lms/services/organization.py b/lms/services/organization.py index ed80e53920..feb2d702cc 100644 --- a/lms/services/organization.py +++ b/lms/services/organization.py @@ -19,11 +19,11 @@ LOG = getLogger(__name__) -class InvalidOrganizationParent(Exception): +class InvalidOrganizationParent(Exception): # noqa: N818 """The requested Organization wasn't found or isn't an eligible parent.""" -class InvalidPublicId(Exception): +class InvalidPublicId(Exception): # noqa: N818 """Indicate an error with the specified public id.""" diff --git a/lms/services/user.py b/lms/services/user.py index 95053688c2..4ef89a09b5 100644 --- a/lms/services/user.py +++ b/lms/services/user.py @@ -22,7 +22,7 @@ from lms.services.upsert import bulk_upsert -class UserNotFound(Exception): +class UserNotFound(Exception): # noqa: N818 """The requested User wasn't found in the database.""" diff --git a/lms/services/vitalsource/_client.py b/lms/services/vitalsource/_client.py index 580304a44d..0cb5573e10 100644 --- a/lms/services/vitalsource/_client.py +++ b/lms/services/vitalsource/_client.py @@ -15,7 +15,7 @@ LOG = logging.getLogger(__name__) -class BookNotFound(SerializableError): +class BookNotFound(SerializableError): # noqa: N818 def __init__(self, book_id): super().__init__(message=f"Book {book_id} not found") diff --git a/lms/services/vitalsource/exceptions.py b/lms/services/vitalsource/exceptions.py index ddd11e8442..0db12e3f2d 100644 --- a/lms/services/vitalsource/exceptions.py +++ b/lms/services/vitalsource/exceptions.py @@ -5,7 +5,7 @@ class VitalSourceError(SerializableError): """Indicate a failure in the VitalSource service or client.""" -class VitalSourceMalformedRegex(VitalSourceError): +class VitalSourceMalformedRegex(VitalSourceError): # noqa: N818 """An issue with the user regex.""" def __init__(self, description, pattern): diff --git a/lms/services/youtube.py b/lms/services/youtube.py index 25d1faa2b2..f9b789d993 100644 --- a/lms/services/youtube.py +++ b/lms/services/youtube.py @@ -5,7 +5,7 @@ """YouTube's API base URL""" -class VideoNotFound(SerializableError): +class VideoNotFound(SerializableError): # noqa: N818 def __init__(self, video_id): super().__init__( error_code="youtube_video_not_found", details={"video_id": video_id} diff --git a/lms/views/api/sync.py b/lms/views/api/sync.py index 07e2406911..0ace7c2264 100644 --- a/lms/views/api/sync.py +++ b/lms/views/api/sync.py @@ -11,7 +11,7 @@ class APISyncSchema(PyramidRequestSchema): context_id = fields.Str(required=True) group_set_id = fields.Str(required=False, allow_none=True) group_info = fields.Dict(required=True) - gradingStudentId = fields.Str(required=False, allow_none=True) + gradingStudentId = fields.Str(required=False, allow_none=True) # noqa: N815 @view_config( diff --git a/pyproject.toml b/pyproject.toml index 8c44689175..6fd4333cc7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ select = [ "R", "PLR", # https://docs.astral.sh/ruff/rules/#refactor-r "C", "PLC", # https://docs.astral.sh/ruff/rules/#convention-c "SLF", # flake-8-self + "N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n "RUF100", # unused-noqa ]