pyerrors icon indicating copy to clipboard operation
pyerrors copied to clipboard

[Feat] Add type hints

Open fjosw opened this issue 1 year ago • 11 comments

As a first step towards adding type hints, I added automatic type hints with monkeytype. Hints for the more complicated methods will need additional manual work but for the simpler methods this seems to have worked quite well.

fjosw avatar Dec 25 '24 10:12 fjosw

Not quite done but already in decent shape for a review @s-kuberski @jkuhl-uni:

  • Most of the changes are just type annotations
  • I changed a few lines to help mypy with understanding the type annotations
  • I fixed a few smaller bugs in which explicit type checks were not consistent or did not cover certain edge cases

For now I ignored the input/* modules and most of correlators.py, the remaining modules only raise a few smaller mypy errors which I wasn't able to fix right away.

fjosw avatar Jan 03 '25 18:01 fjosw

Great, thanks a lot for all of your work! I'll have a look in the upcoming week.

s-kuberski avatar Jan 05 '25 14:01 s-kuberski

Hey @fjosw, thanks for all the work, I am looking through it right now, it looks excellent to me. I hope it was okay that I pushed a few small changes. If not, feel free to revert them, as you please :)

jkuhl-uni avatar Jan 09 '25 09:01 jkuhl-uni

Thansk again for starting this. I'm still in correlators.py and have discovered quite a few places, where I think that the type hints should be changed, if one wants them to be correct. What's our strategy? Shall I continue to point them out and you change them if you agree? Or shall I directly adapt? I guess it's not breaking anything if some of the hints are incorrect, but if we introduce them in the first place, I think we should make an effort to have them correct and hopefully complete.

s-kuberski avatar Jan 10 '25 14:01 s-kuberski

Feel free to get started with fixing stuff, you should have permissions to push to the branch, I think I won't have time to work on this in the comming days. My strategy so far was to run mypy to point out typing issues and go from there. As @jkuhl-uni suggested it might be worth defining a Obs-like type which can then be used for the overloaded methods.

fjosw avatar Jan 10 '25 14:01 fjosw

I've tried to go through the changes and to address the issues that I raise above and a few more things.

s-kuberski avatar Feb 17 '25 14:02 s-kuberski

I resolved the merge conflicts and fixed a few smaller issues but now one of the tests test_rwms is failing. Can you have a look @jkuhl-uni ?

fjosw avatar May 05 '25 17:05 fjosw

I had a look and found a solution for now, there are a few minor things to figure out. I hope to get it done today :)

jkuhl-uni avatar May 07 '25 07:05 jkuhl-uni

... well that was easy. I'd like to disentangle some of the openQCD tests (in test_rwms we are testing the read_rwms, extract_t0 and extract_w0 methods), but I'll do that in a different PR.

jkuhl-uni avatar May 07 '25 07:05 jkuhl-uni

Thanks a lot @jkuhl-uni ! As we have accumulated quite a few changes I would suggest that we all do a thorough review and then merge this first version with type hints which we can refine later @s-kuberski @jkuhl-uni .

fjosw avatar May 07 '25 15:05 fjosw

Hi, I looked through the code again and made mainly small changes, as to improve some type hints. The PR looks good to me otherwise.

jkuhl-uni avatar Nov 04 '25 10:11 jkuhl-uni