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 type hints to graphing #4118

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

fmuenkel
Copy link
Contributor

Overview: What does this pull request change?

Related to #3375.

Motivation and Explanation: Why and how do your changes improve the library?

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

self.parametric_function: Callable[[float], Point3D] = lambda t: np.array(
[t, function(t), 0]
)
self.function = function # type: ignore[assignment]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know how to resolve this.

f"Expected a float type result, got {type(result)}."
)
return result
return np.log(value) / np.log(base) # type: ignore [no-any-return]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to resolve this type hint error.

@@ -141,7 +141,7 @@ def __init__(self, base: float = 10, custom_labels: bool = True) -> None:

def function(self, value: float) -> float:
"""Scales the value to fit it to a logarithmic scale.``self.function(5)==10**5``"""
return float(self.base**value)
return self.base**value # type: ignore [no-any-return]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know yet how to resolve this.

@henrikmidtiby
Copy link
Contributor

Nice to see more typing work! I have also added type annotations for the graphing/scale.py in #4125, but it seems like you have also updated some warnings in the code that I haven't dealt with.

Regarding the [no-any-return] type errors I would suggest you to first save the value in a variable that you can assign the type and then return the value like shown here:

val: float = np.log(value) / np.log(base)
return val

@fmuenkel fmuenkel mentioned this pull request Jan 21, 2025
22 tasks
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