-
Notifications
You must be signed in to change notification settings - Fork 142
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
Parcels typing and mypy support #1653
Comments
@erikvansebille configuring Ruff at the moment. Default line length is 88, thoughts on having it be 120? Some discussion on line length. I think 120 would be good to avoid re-wrapping large conditionals across multiple lines, which we seem to have some of. If we want we can work to reducing this in future.
You can visually see what this looks like by adding a ruler in VScode:
Overviews120 line length "git diff --stat"
88 line length "git diff --stat"
|
Thanks for looking into this, @VeckoTheGecko. Actually, I'm not against 88 line width, I think. Yes, it will lead to more lines, but especially on browsers it's easier to read. So I think my vote would be for 88? |
@erikvansebille Hmm, yes I agree with the 88 line width wrt. browsers and the docs. Maybe we can do 88 for everything in the docs folder (notebooks/scripts) and then 120 for the rest? Ruff is quite configurable on a file level so this should be fine. My main concern is readability, since the diff created by 88 really makes files like EDIT: fixed the patches |
Ah interesting; if we can do it on a directory/file-level then let's go with 88 for |
I think 88 for data = {
"U": np.array(U, dtype=np.float32),
"V": np.array(V, dtype=np.float32),
"psu_salinity": np.array(psu_salinity, dtype=np.float32),
"cons_pressure": np.array(cons_pressure, dtype=np.float32),
"cons_temperature": np.array(cons_temperature, dtype=np.float32),
} don't get collapsed to one line. I'll make it a separate PR since its a huge diff |
Adding type annotations in the codebase will improve our documentation, improve linting (where users can hover over and quickly see types of variables), as well as allow for typechecking through
mypy
Pyright (should we implement it).I was initially hesitant for this because I remembered the python community as a whole seems very split on this (and I also had some difficulties using mypy in the past). Revisiting it, I've seen some strong support especially with newer Python versions. I have also found out that https://github.com/python/typeshed provides "stubs" providing types for untyped packages.
Considerations:
fieldset.py
are a culpritparcels.typing
module to store type aliases commonly used in the codebase (e.g., for dimension mapping dictionaries which are of an expected format)typing
module and the types provided in thereRelated: #1324
EDIT: Pyright was investigated. Seems that its stricter than
mypy
. At the moment just opting for mypy. See some discussion for more contextThe text was updated successfully, but these errors were encountered: