Skip to content

Commit

Permalink
Typing fix: Narrow optional types with asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Mar 14, 2024
1 parent b443f36 commit f0e801d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions lms/events/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@subscriber(BaseEvent)
def handle_event(event: BaseEvent):
"""Record the event in the Event model's table."""
assert event.request
event.request.find_service(EventService).insert_event(event)
3 changes: 3 additions & 0 deletions lms/services/vitalsource/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ def page_ranges_enabled(self) -> bool:

def get_book_info(self, book_id: str) -> dict:
"""Get details of a book."""
assert self._metadata_client

return self._metadata_client.get_book_info(book_id)

def get_table_of_contents(self, book_id: str) -> list[dict]:
"""Get the table of contents for a book."""
assert self._metadata_client

return self._metadata_client.get_table_of_contents(book_id)

Expand Down Expand Up @@ -157,6 +159,7 @@ def get_sso_redirect(self, document_url, user_reference: str) -> str:
:param user_reference: The user reference (you can use
`get_user_reference()` to help you with this)
"""
assert self._sso_client
return self._sso_client.get_sso_redirect(
user_reference, self.get_book_reader_url(document_url)
)
Expand Down

0 comments on commit f0e801d

Please sign in to comment.