-
Notifications
You must be signed in to change notification settings - Fork 13
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
Clean documentation and add type hints #228
Conversation
I am not against typing, however we should do it properly have you considered using mypy and /or ruff (the The trajectory module is a great starting point for its usage, and would likely complement the docstring to help people play with them. A few comments:
|
Good point. I followed ruff's ANN rule, and the current code is compliant (except for bad usage of Literal apparently)
Done, but some cases like open kwargs are still relevant. I tried to reduce them to a minimum though.
Make sense. The CI tells me I underestimated
Make sense.
Done, but I have to check also how it renders in docstrings |
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.
We are on a good path, thanks for the tedious work.
Do not hesitate to check your modification with mypy locally. I am also pretty sure an LLM could help you adding annotation in bulk if needed...
src/mrinufft/trajectories/display.py
Outdated
"""Restore the display configuration.""" | ||
for key, value in self._old_values.items(): | ||
setattr(displayConfig, key, value) | ||
delattr(self, "_old_values") | ||
|
||
def __enter__(self): | ||
def __enter__(self) -> "displayConfig": |
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 you use from __future__ import annotations
you should be able to annotate with the Class directly, not a string :)
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.
Delayed annotation checks helped in several cases actually, thx !
src/mrinufft/trajectories/display.py
Outdated
constraints_order=None, | ||
**constraints_kwargs, | ||
): | ||
trajectory: np.typing.NDArray, |
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.
I think you can just from numpy.typing import NDArray
and use it everywhere
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.
Done, much better indeed
*, | ||
diagonals: bool = True, | ||
pseudo_random: bool = True, | ||
**sampling_kwargs: Literal | bool, |
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.
Literal
has to be used as Literal["A string"]
or Literal[1]
for instance
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.
Done. Most Literal
uses were actually unjustified because of the way we handle Enum
for everything
diagonals: bool = True, | ||
pseudo_random: bool = True, | ||
**sampling_kwargs: Literal | bool, | ||
) -> np.ndarray: |
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.
should be NDArray
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.
Yes I missed a lot of them for some reason, thx
|
first_cluster_by: Literal["x", "y", "z", "r", "phi", "theta"] | None = None, | ||
second_cluster_by: Literal["x", "y", "z", "r", "phi", "theta"] | None = None, | ||
sort_by: Literal["x", "y", "z", "r", "phi", "theta"] | None = None, |
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.
I think you can:
- Use a type alias (declared below the imports), for brievety
- Put the None inside the literal
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.
- Done for the type alias, thx
- There is one function where
None
is not an acceptable option so I kept it out
Just cleaning the documentation a bit and adding type hints