-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add some typehints in core/helpers.py #9788
Add some typehints in core/helpers.py #9788
Conversation
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.
Thanks for this, @yivgen. Just a few bits of feedback.
openlibrary/core/helpers.py
Outdated
import babel | ||
import babel.core | ||
import babel.dates | ||
import babel.numbers | ||
|
||
from babel.core import Locale | ||
from typing import Optional |
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.
from typing import Optional |
openlibrary/core/helpers.py
Outdated
@@ -196,7 +212,7 @@ def sprintf(s, *a, **kw): | |||
return s | |||
|
|||
|
|||
def cond(pred, true_value, false_value=""): | |||
def cond(pred, true_value, false_value): |
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.
def cond(pred, true_value, false_value): | |
def cond(pred: Any, true_value: Any, false_value: Any = "") -> Any: |
Good call on not putting list[Author]
here, etc., as that could be misleading, given all the possible valid things one could supply here.
My suggestion, using Any
, is of questionable value, but it least it lets others know the function has been considered vis-a-vis typing.
The main thing is that we'll want to keep the ""
default value for false_value
, so we don't make false_value
a required argument for calling functions that may now rely on it having a default.
openlibrary/core/helpers.py
Outdated
if TYPE_CHECKING: | ||
from openlibrary.plugins.upstream.models import Author | ||
|
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.
if TYPE_CHECKING: | |
from openlibrary.plugins.upstream.models import Author |
Because Author
isn't used, this won't be needed.
openlibrary/core/helpers.py
Outdated
from typing import TYPE_CHECKING | ||
|
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.
from typing import TYPE_CHECKING |
Because Author
isn't used, this won't be needed.
Thank you for the informative feedback! I'll add all of these changes |
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.
Great work. Thanks for this, @yivgen.
Related to #8028
Adds typehints in core/helpers.py
Technical
Testing
Screenshot
Stakeholders
@scottbarnes