Skip to content

Commit

Permalink
Fix all mypy's attr-defined issues in the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed May 10, 2024
1 parent bf71f34 commit 91d1cb0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions lms/scripts/init_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# mypy: disable-error-code="attr-defined"
"""
Initialize the DB.
Expand Down
30 changes: 26 additions & 4 deletions lms/services/moodle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from typing import Literal, NotRequired, TypedDict

from lms.services.aes import AESService
from lms.services.exceptions import ExternalRequestError
Expand All @@ -22,6 +23,23 @@ class Function(str, Enum):
"""Returns a list of pages in a provided list of courses."""


class File(TypedDict):
"""Represents a file or folder in an LMS's file storage."""

type: Literal["File", "Folder"]
mime_type: NotRequired[Literal["text/html", "application/pdf", "video"]]

id: str
"""ID in our system"""
lms_id: str
"""Raw ID in the LMS"""

display_name: str

updated_at: NotRequired[str]
children: NotRequired[list["File"]]


class MoodleAPIClient:
API_PATH = "webservice/rest/server.php"

Expand Down Expand Up @@ -141,9 +159,13 @@ def page(self, course_id, page_id) -> dict | None:
}

def list_pages(self, course_id: int):
root: File = { # type:ignore
"type": "Folder",
"display_name": "",
"children": [],
}
contents = self.course_contents(course_id)
root = {"type": "Folder", "display_name": "", "children": []}
folders = {root["display_name"]: root}
folders: dict[str, File] = {root["display_name"]: root}

for topic in contents:
topic_name = topic["name"]
Expand All @@ -153,7 +175,7 @@ def list_pages(self, course_id: int):
# Pages can only be at the top level modules
if module["modname"] == "page":
if topic_name not in folders:
new_folder = {
new_folder: File = {
"type": "Folder",
"display_name": topic_name,
"id": f"{course_id}-{topic_name}",
Expand All @@ -172,7 +194,7 @@ def list_pages(self, course_id: int):
)
updated_at = page_index[0]["updated_at"] if page_index else None

file_node = {
file_node: File = {
"type": "File",
"mime_type": "text/html",
"display_name": module["name"],
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ project_type = "application"
python_version = 3.11

disable_error_code = [
"attr-defined",
"import-untyped",
]

Expand Down

0 comments on commit 91d1cb0

Please sign in to comment.