-
Notifications
You must be signed in to change notification settings - Fork 66
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, and use mypy to enforce in CI #16
Comments
Hi @HGSilveri @karalekas, I went through the issue and would like to work on it. I have a few questions, I found this GitHub Action which can be used to implement the type hint ci, so can it be used? or do it need to be implemented using shell script? |
Hi @TripleR47, I've done it for the |
Hi @TripleR47, no preference regarding how the mypy checks are occur, as long as they are programmed into the existing workflow, if that's what you're asking. But bear in mind that is not the crux of the PR, but rather going through the existing code and adding the appropriate type hints to each function and method. After that's done, then you can incorporate |
Okay, I'll ask in the unitaryHack's server if anyone wants to collaborate on this issue. Can it be assigned to me? |
Hi @LaurentAjdnik, wanna collaborate on this issue? |
👍 |
Are you in unitaryfund's discord server? If you are then DM me on discord, we can discuss further on this. |
@TripleR47 @LaurentAjdnik So, can I assign it to you both? |
Sure |
Yup! Your feedback on #155, in which I added type hints, will be insightful for the current issue. Then, we can sync with @TripleR47. |
|
@TripleR47: Nope, not on Discord. I'm waiting for the feedback on #155 and we can move on from there. Adding type hints will be pretty straightforward. Maybe we can dispatch classes between us. @HGSilveri: Will you be in charge of adding mypy to CI workflow ? |
@LaurentAjdnik : I'll review #155 first thing on Monday. And yes, I can add it to the CI no problem. I would advise you to use it to test your own typing as you go. Did you try it already on #155? |
Running MyPy on #155 (screenshots below):
With the Without the |
…), Enhanced `ValueError` messages (#148), Type hinting for `Register` (#16) (#155) * Update register.py * Add max_connectivy() * Test * Adding hexagon() and max_connectivity() * Type hinting and parameters checks * Shift atom generation in full layers for consistency * Remove unused variables to avoid flake8 warnings * Corrections for PR #155
Hi @TripleR47! Have you been working on it ? PR #155 has been approved and type-checked with MyPy beforehand. We could use it as an inspiration. |
Yes, I have been going through mypy and Pulser documentations and have started working on the devices module. @LaurentAjdnik, let's split up the rest of the modules. |
Great! I'll start working on |
Hi again @TripleR47! I just PR-ed #163 on |
Hi again @TripleR47 and @HGSilveri, I start working on |
Okay, I'm almost done with the devices module, will start working on parametrized and simulation after that. |
Great! I'll start working on |
Okay! I'm done with the parametrized module, start working on simulation next. |
Hi @LaurentAjdnik , @TripleR47 ! Glad to see you're making progress. I just wanted to clarify a few things:
Keep up the good work! |
Sorry, I started PR-ing without respecting this order... And the branch I'm working on will include all remaining files in the root directory... I feel like type-hinting everything will soon be over. Hence, if the corresponding PRs pass the existing checks (without |
I'd rather not merge to develop without |
Okay @HGSilveri, @LaurentAjdnik if you haven't started working on |
Well, I've finished working on it. All files in root are done. I might have to split this unique new branch so that @HGSilveri can arrange the merging order. |
Okay, I have also finished the |
* Add type hints * Set @DataClass to init=True Co-authored-by: Henrique Silvério <[email protected]>
* Add type hints to `waveforms.py` * PR #163 after comments * Remove "import Union" no longer necessary * Change `Callable` to `FunctionType` * list[Waveform] * List[Waveform] * Add type hints for `Parametrized` * Add Parametrized hints to each __init__ * Add more type hints * Add more type hints * Change __init__ for BlackmanWaveForm * Update type hints * Update type hints * Check type of area * Update type hints * Correct last typo Co-authored-by: Henrique Silvério <[email protected]>
* Add type hints in pulser.parametrized * Update style and type hints in pulser.parametrized * Update type hints in pulser.parametrized * Update test_parametrized.py * Update type hints in paramobj.py and variable.py * Update type hint in paramabc.py and paramobj.py * Update in paramabc.py * Update in paramabc.py * Update paramabc.py * Update paramobj.py * Update paramobj.py * Update paramabc.py and paramobj.py Co-authored-by: Henrique Silvério <[email protected]>
Hey @LaurentAjdnik, which test modules are you working on? |
Hi @TripleR47, I'm done with all files in the root directory. I haven't planned working on test files. @HGSilveri: Does it make sense anyway? |
I would say no, not really. |
Okay |
…16) (#169) * Add type hints in _device_datacls.py * Add type hints in coders.py * Update style edits in _device_datacls.py and coders.py * Update type hints in _device_datacls.py * Update type hints in coders.py * Update type hints in coders.py * Update coders.py Co-authored-by: Henrique Silvério <[email protected]>
So, I was convinced that using "parametrized generics" for type-hinting using built-ins (e.g. I don't like the inconsistency of having both forms, so I guess we should adopt the most modern one throughout, which is to use the built-ins (i.e., I have been asking you to do the opposite up until now, so it's only fair I make a PR enforcing these changes for all the type-hints that have already been merged. However, it would be good if you could change this on the PRs that are still open. |
Okay |
@TripleR47, bear in mind that you still can only do this in the type annotations. This means, for example, that you can't do |
Okay, and what about the special types like Callable, Union etc. Do we have their alternatives in the built-ins? |
No, those stay the same. Refer to this list for the built-in generics that replace those in |
Okay, thanks! |
@TripleR47 : From that list, notice that |
* Add type hints to sequence.py * Update type hints in `sequence.py` * Update type hints in `sequence.py` * Introduce QubitId type * Update QubitId definition * Use built-in type hints * Resolve merge conflicts * Switch tuple to Tuple * Update with PR comments * Update with PR comments * Add NamedTuple type hint * Import Literal from typing_extensions * Update with PR comments * Change Set back to Iterable * Change Iterable[QubitId] to Iterable * Change comment to docstring * Import Literal and get_args depending on version * Add another # pragma: no cover * Rearrange imports * Rearrange imports * Add a line, just a line Co-authored-by: Henrique Silvério <[email protected]>
* Add type hints in pulser.simulation * Update type hints in simresults.py * Update type hints in simulation.py Co-authored-by: Henrique Silvério <[email protected]>
* Add type hints * Add type hints * Merge branch * Sync branches * Resolve conflicts * Update _seq_drawer.py * Update _seq_drawer.py * Update _seq_drawer.py Co-authored-by: Henrique Silvério <[email protected]>
Solved by @LaurentAjdnik and @TripleR47 , thank you both for your patience and hard work! |
@HGSilveri, thanks for your guidance! 😃 |
Python is a dynamically-typed language (see: duck typing), but Python 3.5 and pep-484 introduced type hints as a way to annotate Python code with types. These are not enforced by the language at runtime, but they can be checked by third-party libraries such as mypy. The impetus for adding type hints and using mypy is that they generally encourage developers to write saner, simpler code (the flexibility of Python is a double-edged sword). This issue is mostly about good code style and therefore is optional -- it doesn't block CI setup (but once it is complete, the CI can be used to do this type checking automatically).
The text was updated successfully, but these errors were encountered: