Skip to content

Commit

Permalink
Disable pylint rules not supported by pylint
Browse files Browse the repository at this point in the history
no-member
too-many-instance
unsupported-assignment-operation
abstract-method
cyclic-import
too-many-ancestors
  • Loading branch information
marcospri committed May 27, 2024
1 parent 99a5d64 commit f12e0ad
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 203 deletions.
2 changes: 1 addition & 1 deletion lms/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@dataclass
class BaseEvent: # pylint:disable=too-many-instance-attributes
class BaseEvent:
"""Base class for generic events."""

type: EventType.Type
Expand Down
2 changes: 1 addition & 1 deletion lms/models/_mixins/public_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _get_current_region():
return Region(code=environ["REGION_CODE"], authority=environ["H_AUTHORITY"])


class _PublicIdComparator(Comparator): # pylint: disable=abstract-method, too-many-ancestors
class _PublicIdComparator(Comparator):
"""A comparator for covering over details of comparing public ids."""

def __eq__(self, other):
Expand Down
4 changes: 2 additions & 2 deletions lms/models/json_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def set(self, group, key, value):
:param key: The key in that group
:param value: The value to set
"""
# pylint:disable=unsupported-assignment-operation

super().setdefault(group, {})[key] = value

def set_secret(self, aes_service, group, key, value: str) -> None:
Expand All @@ -116,7 +116,7 @@ def set_secret(self, aes_service, group, key, value: str) -> None:

# Store both the setting and the IV
# We can't store the bytes directly in JSON so we store it as base64
# pylint:disable=unsupported-assignment-operation

super().setdefault(group, {})[key] = base64.b64encode(encrypted_value).decode(
"utf-8"
)
Expand Down
2 changes: 1 addition & 1 deletion lms/models/lti_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _apply_canvas_quirks(lti_params, request):

# This is canvas only, call the right plugin directly
# Importing the plugin here to avoid a circular dependency hell
from lms.product.canvas._plugin.misc import ( # pylint:disable=import-outside-toplevel, cyclic-import
from lms.product.canvas._plugin.misc import ( # noqa: PLC0415
CanvasMiscPlugin,
)

Expand Down
2 changes: 1 addition & 1 deletion lms/models/lti_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LTI:


@dataclass
class LTIUser: # pylint: disable=too-many-instance-attributes
class LTIUser:
"""An LTI user."""

user_id: str
Expand Down
2 changes: 1 addition & 1 deletion lms/resources/_js_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def enable_lti_launch_mode(self, course, assignment: Assignment):
},
}

def enable_file_picker_mode( # pylint:disable=too-many-arguments
def enable_file_picker_mode( # noqa: PLR0913
self,
form_action,
form_fields,
Expand Down
2 changes: 1 addition & 1 deletion lms/services/email_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InvalidTokenError(Exception):


@dataclass(frozen=True)
class EmailPrefs: # pylint:disable=too-many-instance-attributes
class EmailPrefs:
DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]

h_userid: str
Expand Down
4 changes: 1 addition & 3 deletions lms/services/h_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ def get_course_stats(self, group_authority_ids: list[str]):
)
return response.json()

def _api_request(
self, method, path, body=None, headers=None, stream=False
): # noqa: PLR0913
def _api_request(self, method, path, body=None, headers=None, stream=False): # noqa: PLR0913
"""
Send any kind of HTTP request to the h API and return the response.
Expand Down
1 change: 0 additions & 1 deletion lms/services/lti_grading/_v11.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from lms.services.oauth1 import OAuth1Service


# pylint:disable=abstract-method
class LTI11GradingService(LTIGradingService):
# See: LTI1.1 Outcomes https://www.imsglobal.org/specs/ltiomv1p0/specification
def __init__(
Expand Down
1 change: 0 additions & 1 deletion lms/services/lti_role_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def get_roles(self, role_description: str) -> list[LTIRole]:
"""
role_strings = [role.strip() for role in role_description.split(",")]

# pylint: disable=no-member
# Pylint is confused about the `in_` for some reason
roles = self._db.query(LTIRole).filter(LTIRole.value.in_(role_strings)).all()

Expand Down
3 changes: 1 addition & 2 deletions lms/tasks/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

@app.task
def insert_event(event: dict) -> None:
with app.request_context() as request: # pylint: disable=no-member
with app.request_context() as request:
with request.tm:
# pylint:disable=cyclic-import
from lms.services.event import EventService # noqa: PLC0415

request.find_service(EventService).insert_event(
Expand Down
2 changes: 1 addition & 1 deletion lms/tasks/rsa_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def rotate_keys():
"""Periodically (based on h-periodic) rotate RSA keys."""

with app.request_context() as request: # pylint: disable=no-member
with app.request_context() as request:
if request.registry.settings["disable_key_rotation"]:
# Useful for environments where keys might be hardcoded on the LMS side
# like the local environment and QA
Expand Down
4 changes: 1 addition & 3 deletions lms/validation/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from pyramid import httpexceptions
from pyramid.httpexceptions import HTTPFound

# pylint: disable=too-many-ancestors

__all__ = ["ValidationError", "LTIToolRedirect"]


class ValidationError(httpexceptions.HTTPUnprocessableEntity): # pylint: disable=too-many-ancestors
class ValidationError(httpexceptions.HTTPUnprocessableEntity):
"""
A schema validation failure.
Expand Down
1 change: 0 additions & 1 deletion lms/validation/authentication/_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from lms.validation._exceptions import ValidationError

# pylint: disable=too-many-ancestors
# ValidationError has a large hierarchy, but we need to inherit from it

__all__ = [
Expand Down
4 changes: 2 additions & 2 deletions lms/views/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def assignment_redirect_from_launch(self):
response = HTTPFound(
location=self.request.route_url(
"dashboard.assignment",
# pylint:disable=protected-access
public_id=self.request.lti_user.application_instance.organization._public_id, # noqa: SLF001
assignment_id=assignment_id,
),
Expand Down Expand Up @@ -92,7 +91,8 @@ def _set_lti_user_cookie(self, response):
# An LTIUser might not exists if accessing from the admin pages.
return response
auth_token = (
BearerTokenSchema(self.request).authorization_param(lti_user)
BearerTokenSchema(self.request)
.authorization_param(lti_user)
# White space is not allowed as a cookie character, remove the leading part
.replace("Bearer ", "")
)
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ disable = [
"import-outside-toplevel",
"too-many-statements",
"protected-access",

# Not supported by ruff
"too-many-ancestors",
"abstract-method",
"cyclic-import",
"unsupported-assignment-operation",
"too-many-instance-attributes",

# Mostly false positives, better served by mypy
"not-callable",
"no-member",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lms/views/dashboard/views_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: SLF001
from unittest.mock import create_autospec, sentinel

import pytest
Expand All @@ -12,7 +13,6 @@
pytestmark = pytest.mark.usefixtures("h_api", "assignment_service", "course_service")


# pylint:disable=protected-access
class TestDashboardViews:
@freeze_time("2024-04-01 12:00:00")
def test_assignment_redirect_from_launch(
Expand Down
180 changes: 0 additions & 180 deletions tests/unit/lms/views/dashboard_test.py

This file was deleted.

0 comments on commit f12e0ad

Please sign in to comment.