Repository navigation
Convert typing to PEP604 - #5531
Conversation
Documentation build overview
86 files changed ·
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5531 +/- ##
========================================
Coverage 93.92% 93.93%
========================================
Files 184 184
Lines 22661 22662 +1
Branches 3223 3223
========================================
+ Hits 21284 21287 +3
+ Misses 917 915 -2
Partials 460 460 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
An example of docstring fixes are the now properly linked vs the current docs which was incorrect ( |
tylerjereddy
left a comment
There was a problem hiding this comment.
I added a few comments from skimming over--I guess those are mostly things that can be done in follow-ups.
If we decide to get pretty serious about typing, for big decision we should ask Joren H. to weigh in--it is hard to do typing correctly..
| int | ||
| Step size for iteration. Always a positive integer greater than 0. | ||
|
|
There was a problem hiding this comment.
some extra whitespace changes are coming in
|
Beyond that, the changes mostly look fine/straightforward, though I only scanned the first 70 % of the diff or so. |
|
Currently the only thing I am unsure about is |
tylerjereddy
left a comment
There was a problem hiding this comment.
I read through the full diff manually. I think this is a net improvement so I'll give it an approval. I suggest adding the PR number to the CHANGELOG entry and self-merging.
I do believe there's more we could still modernize, even in this diff, as my comment about forward referenced string typing suggests.
That said, I suspect if there's an appetite for going all in on static typing, it might be good to have some kind of plan and a decision on which static type checkers to add in CI (probably more of them, and also the the primer that checks knock-on effects of typing changes to the rest of the ecosystem). But that's for other issue(s)/PR(s).
| start: Optional[int]=None, stop: Optional[int]=None, | ||
| step: Optional[int]=None, | ||
| order: Optional[str]='fac') -> np.ndarray: | ||
| def timeseries(self, asel: 'AtomGroup | None'=None, |
There was a problem hiding this comment.
I'm pretty sure that using string typing like this can be completely avoided these days, but maybe best for a follow-up...
There was a problem hiding this comment.
I think in this case it would be circular? Because we have to import AtomGroup inside of TYPE_CHECKING to avoid it being circular, so we can't use the actual class and have to use the string version. Unless there is a way around this I am unaware of.
if TYPE_CHECKING:
from ..core.groups import AtomGroup|
Thanks for the thorough review @tylerjereddy ! Appreciate it, and welcome any thoughts for improved typing going forward. |
Moving the annotations to separate type stubs is one way. The other is as the PEP on circular and forward references describes: https://peps.python.org/pep-0649/. You used to need to do |
Our minimal supported Python version is now
3.11, so we can adoptPEP604type syntax:typing.Optional[X]->X | Nonetyping.Union[A, B]->A | BThere are lots of regions that are lacking types all together, but ahead of a broader effort to improve formatting and type hinting, this aligns current types with modern standards.
Changes made in this Pull Request:
value: int = None->value: int | None = None)np.array->np.ndarray)np.ndarray->numpy.ndarray)LLM / AI generated code disclosure
LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no
(this was quite therapeutic to do by hand, brushing off my regex)
PR Checklist
package/CHANGELOGfile updated?package/AUTHORS? (If it is not, add it!)Developers Certificate of Origin
I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.