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

Duck-Typing In Certain Functions #41

Open
AFg6K7h4fhy2 opened this issue Nov 18, 2024 · 2 comments
Open

Duck-Typing In Certain Functions #41

AFg6K7h4fhy2 opened this issue Nov 18, 2024 · 2 comments
Assignees
Labels
enhancement Enhancement to existing feature or aspect of the project. Low Priority A task that is of lower relative priority.

Comments

@AFg6K7h4fhy2
Copy link
Collaborator

While Python does not require strict typing and while strict typing is useful in certain instances, there are some instances within forecasttool-py where the author's strict-typing approaches are overly pedantic. As a replacement for these situations, such as in add_time_coords_to_idata_dimension,

inputs = [
        (idata, az.InferenceData, "idata"),
        (group, str, "group"),
        (variable, str, "variable"),
        (dimension, str, "dimension"),
        (time_step, timedelta, "time_step"),
    ]
for value, expected_type, param_name in inputs:
    forecasttools.validate_input_type(
        value=value, expected_type=expected_type, param_name=param_name
    )

DHM suggests adhering to Duck typing.

@AFg6K7h4fhy2 AFg6K7h4fhy2 added the enhancement Enhancement to existing feature or aspect of the project. label Nov 18, 2024
@AFg6K7h4fhy2 AFg6K7h4fhy2 self-assigned this Nov 18, 2024
@AFg6K7h4fhy2
Copy link
Collaborator Author

From DHM comments in #35 :

        (groups, (str, list), "groups"),
        (variables, (str, list), "variables"),
        (dimensions, (str, list), "dimensions"),

Again, I think this can be duck-typed, especially as you're going to call ensure_listlike on them

Why error if the user provides a numpy.array of strings, for instance?

and

    forecasttools.validate_iter_has_expected_types(groups, str, "groups")
    forecasttools.validate_iter_has_expected_types(variables, str, "variables")
    forecasttools.validate_iter_has_expected_types(
        dimensions, str, "dimensions"
    )

Again, this feels like unnecessarily strong typing for a duck-y language, but I am less opposed here than I am above.

@AFg6K7h4fhy2
Copy link
Collaborator Author

AFg6K7h4fhy2 commented Dec 6, 2024

The following resource seems useful:

Screenshot 2024-12-05 at 19 36 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to existing feature or aspect of the project. Low Priority A task that is of lower relative priority.
Projects
None yet
Development

No branches or pull requests

1 participant