Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mypy errors in course.py #195

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions pittapi/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import re
import requests
from typing import NamedTuple
from typing import NamedTuple, Any

JSON = dict[str, Any]

# https://pitcsprd.csps.pitt.edu/psc/pitcsprd/EMPLOYEE/SA/s/WEBLIB_HCX_CM.H_CLASS_SEARCH.FieldFormula.IScript_ClassSearch?institution=UPITT&term=2244&date_from=&date_thru=&subject=CS&subject_like=&catalog_nbr=&time_range=&days=&campus=PIT&location=&x_acad_career=UGRD&acad_group=&rqmnt_designtn=&instruction_mode=&keyword=&class_nbr=&acad_org=&enrl_stat=O&crse_attr=&crse_attr_value=&instructor_name=&instr_first_name=&session_code=&units=&trigger_search=&page=1
SUBJECTS_API = (
Expand Down Expand Up @@ -358,30 +360,32 @@ def _validate_course(course: str | int) -> str:


# peoplesoft api calls
def _get_subjects() -> dict:
return requests.get(SUBJECTS_API).json()
def _get_subjects() -> JSON:
response: JSON = requests.get(SUBJECTS_API).json()
return response


def _get_subject_courses(subject: str) -> dict:
return requests.get(SUBJECT_COURSES_API.format(subject=subject)).json()
def _get_subject_courses(subject: str) -> JSON:
response: JSON = requests.get(SUBJECT_COURSES_API.format(subject=subject)).json()
return response


def _get_course_info(course_id: str) -> dict:
response = requests.get(COURSE_DETAIL_API.format(id=course_id)).json()
def _get_course_info(course_id: str) -> JSON:
response: JSON = requests.get(COURSE_DETAIL_API.format(id=course_id)).json()
if response["course_details"] == {}:
raise ValueError("Invalid course ID; course with that ID does not exist")
return response


def _get_course_sections(course_id: str, term: str) -> dict:
response = requests.get(COURSE_SECTIONS_API.format(id=course_id, term=term)).json()
def _get_course_sections(course_id: str, term: str) -> JSON:
response: JSON = requests.get(COURSE_SECTIONS_API.format(id=course_id, term=term)).json()
if len(response["sections"]) == 0:
raise ValueError("Invalid course ID; course with that ID does not exist")
return response


def _get_section_details(term: str, section_id: str) -> dict:
response = requests.get(SECTION_DETAILS_API.format(term=term, id=section_id)).json()
def _get_section_details(term: str | int, section_id: str | int) -> JSON:
response: JSON = requests.get(SECTION_DETAILS_API.format(term=term, id=section_id)).json()
if "error" in response:
raise ValueError("Invalid section ID; section with that ID does not exist")
return response
Expand All @@ -396,7 +400,7 @@ def _get_subject_codes() -> list[str]:
return codes


def _get_internal_id_dict(subject: str) -> dict:
def _get_internal_id_dict(subject: str) -> dict[str, str]:
response = _get_subject_courses(subject)
internal_id_dict = {}
for course in response["courses"]:
Expand Down