-
Notifications
You must be signed in to change notification settings - Fork 14
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
Misc typing fixes in not annotated functions #6389
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
|
||
def varchar_enum( # noqa: PLR0913, PLR0917 | ||
|
@@ -8,9 +9,9 @@ def varchar_enum( # noqa: PLR0913, PLR0917 | |
nullable=False, | ||
server_default=None, | ||
unique=False, | ||
) -> sa.Column: | ||
) -> Mapped: | ||
"""Return a SA column type to store the python enum.Enum as a varchar in a table.""" | ||
return sa.Column( | ||
return mapped_column( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is probably a pretty good example of SQLAlchemy cleverness that we'd be better off without. If we want to add Python-only validation to a column, SQLAlchemy has a simple way to do that: https://docs.sqlalchemy.org/en/20/orm/mapped_attributes.html#simple-validators |
||
sa.Enum( | ||
enum, | ||
# In order to maintain maximum flexibility we will only enforce the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from lms.services.canvas_api.client import CanvasAPIClient | ||
from lms.services.exceptions import CanvasAPIPermissionError, FileNotFoundInCourse | ||
|
||
|
||
class CanvasService: | ||
"""A high level Canvas service.""" | ||
|
||
api = None | ||
api: CanvasAPIClient = None # type:ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT this is only here for the tests benefict. Ignore this declaration so all the code below assumes the right type. |
||
|
||
def __init__(self, canvas_api, course_copy_plugin): | ||
self.api = canvas_api | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ def get_by_id(self, id_: int) -> Organization | None: | |
|
||
return self._organization_search_query(id_=id_).one_or_none() | ||
|
||
def get_by_public_id(self, public_id: str) -> list | None: | ||
def get_by_public_id(self, public_id: str) -> Organization | None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was wrong |
||
""" | ||
Get an organization by its public_id. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use this pattern, allowing None in a dataclass field to provide a default in
__post_init__
Ignore the type here to avoid multiple issues about it being nullable all over the place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably just remove the
read_from
feature, it's only used once