Skip to content
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 typing #180

Closed
BSchilperoort opened this issue Jul 28, 2023 · 2 comments · Fixed by #183
Closed

Add typing #180

BSchilperoort opened this issue Jul 28, 2023 · 2 comments · Fixed by #183

Comments

@BSchilperoort
Copy link
Collaborator

Type hints are now quite well supported in Python. Unlike strongly typed languages (e.g. C or Java) these are not enforced on runtime. However, they are very useful both as a developer (to avoid bugs and have code work immediately the first time you run it), and for users (as this allows their IDE to know what type of objects will be returned).

Typing can be added progressively (adding types as we go) or I could go over the codebase and add types everywhere. We have only ~50 functions in total, so that should be quite doable.

Type correctness of the code can be enforced with tools like mypy.

@bdestombe
Copy link
Collaborator

bdestombe commented Jul 28, 2023

Great! Could you maybe add mypy as a test that is allowed to fail? So that while developing we can check how close we are to passing the test.

Could mypy also check whether our function calls from our example notebooks, calls to external functions and function calls from the tests fully obey the typechecking?

@BSchilperoort
Copy link
Collaborator Author

With mypy you can set it to either check for untyped definitions, but by default it does not. It would only check for correctness and not if everything is typed. We can work towards adding typing that way.

Python type checkers also check calls to external functions (if those are typed, but most are nowadays, or have stubs available).

As for tests and the notebooks, I don't think type checking there is necessary. For tests is would create more of a burden: the tests are there to check the functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants