Skip to content

Commit

Permalink
Merge pull request #195 from pittcsc/mypy-course
Browse files Browse the repository at this point in the history
Fix `mypy` errors in `course.py`
  • Loading branch information
tianyizheng02 authored Aug 25, 2024
2 parents 58a08c6 + 18a9ecd commit 24c165c
Showing 1 changed file with 16 additions and 12 deletions.
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

0 comments on commit 24c165c

Please sign in to comment.