Skip to content
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

Conversation

yivgen
Copy link
Contributor

@yivgen yivgen commented Aug 22, 2024

Related to #8028

Adds typehints in core/helpers.py

Technical

Testing

Screenshot

Stakeholders

@scottbarnes

Copy link
Collaborator

@scottbarnes scottbarnes left a 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.

import babel
import babel.core
import babel.dates
import babel.numbers

from babel.core import Locale
from typing import Optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import Optional

@@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines 40 to 42
if TYPE_CHECKING:
from openlibrary.plugins.upstream.models import Author

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if TYPE_CHECKING:
from openlibrary.plugins.upstream.models import Author

Because Author isn't used, this won't be needed.

Comment on lines 11 to 12
from typing import TYPE_CHECKING

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import TYPE_CHECKING

Because Author isn't used, this won't be needed.

@yivgen
Copy link
Contributor Author

yivgen commented Aug 22, 2024

Thank you for the informative feedback! I'll add all of these changes

Copy link
Collaborator

@scottbarnes scottbarnes left a 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.

@scottbarnes scottbarnes self-assigned this Aug 22, 2024
@scottbarnes scottbarnes merged commit bf4bc9d into internetarchive:master Aug 22, 2024
4 checks passed
@yivgen yivgen deleted the 8028/refactor/add-typehints-to-core-helpers branch August 23, 2024 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants