Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds Python type annotations to many functions in accounts/model.py and introduces a runtime type check for the S3 auth URL.
- Added parameter and return type hints across multiple methods.
- Introduced a
TypeErrorcheck if the S3 auth URL is not a string. - Simplified
authenticateby removing the redundantelsebranch.
Comments suppressed due to low confidence (3)
openlibrary/accounts/model.py:73
- The parameter name
hashshadows the built-inhash()function. Consider renaming it tohash_valueorencoded_hashfor clarity.
def verify_hash(secret_key, text, hash) -> bool:
openlibrary/accounts/model.py:289
- Returning
Falsealongside aLinkobject can be confusing for API consumers. Consider returningOptional[Link]and useNoneinstead ofFalsefor the no-link case.
def get_activation_link(self) -> Link | bool:
openlibrary/accounts/model.py:296
- Similar to
get_activation_link, it may be clearer to useOptional[Link]and returnNoneinstead ofFalse.
def get_password_reset_link(self) -> Link | bool:
jimchamp
reviewed
Jul 28, 2025
Comment on lines
+757
to
+762
|
|
||
| if not isinstance(url, str): | ||
| raise TypeError( | ||
| f"Expected 'url' to be a string, got {type(url).__name__} instead" | ||
| ) | ||
|
|
Collaborator
There was a problem hiding this comment.
Was this change intentional? It seems out-of-scope for this PR.
Collaborator
Author
There was a problem hiding this comment.
It is needed to ensure that a string is passed to the get function.
But if we want to just assume the url is always a string we can add a noqa to skip this check here.
openlibrary/accounts/model.py:760: error: Argument 1 to "get" has incompatible
type "Any | None"; expected "str | bytes" [arg-type]
url,
PS: It's needed because once you add types to the function parameters the body of the function is type checked.
jimchamp
approved these changes
Aug 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding typehints where we don't need to change things.
Closes #
Technical
Testing
Screenshot
Stakeholders