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

REF: Introduce typing and type hints #965

Open
asoplata opened this issue Jan 10, 2025 · 2 comments
Open

REF: Introduce typing and type hints #965

asoplata opened this issue Jan 10, 2025 · 2 comments
Labels
docs Documentation and tutorials enhancement New feature or request maint Maintenance refactor testing
Milestone

Comments

@asoplata
Copy link
Collaborator

As per George’s recommendation, we should introduce type hints and typing to our code. This enables use of checkers like mypy https://www.mypy-lang.org/ , which can help with debugging and testing. I believe this is especially helpful with scientific computing in particular:

  • For example, maybe you apply an operation and expect to get a numpy array back, but instead receive an intbecause of a bug or dependency change. Your analysis code (and tests) may process this as if it is a valid scientific output, and pass, but type checking would have prevented this at the beginning.
  • Type hints also significantly improve autocompletion in all code editors.

This may make the frequent use of externals/mne.py::_validate_type() unnecessary.

If we want something similar to _validate_type() that runs EVERY time the code is used at runtime, then once we add our type-hints to our function signatures, we could try using https://github.com/RussBaz/enforce . That way, we get all the advantages of typing using the language-standard way, but also enforce our runtime checks. I personally think that using mypy at commit-time, instead of every run-time, is good enough, however.

@asoplata asoplata added maint Maintenance enhancement New feature or request docs Documentation and tutorials refactor testing labels Jan 10, 2025
@asoplata asoplata added this to the 0.5 milestone Jan 10, 2025
@jasmainak
Copy link
Collaborator

reading the MNE conversation, I realized where my thoughts come from ;-) some legitimate concerns expressed there -- and I'd add that it might be a good idea to scour other open source repos to see if others are adopting it. I typically try to avoid being on the bleeding edge ... let others make the mistakes and learn from them. There is also the concern of an added dependency, but I suppose mypy is a well-supported repo so that concern is minor

@ntolley
Copy link
Contributor

ntolley commented Jan 12, 2025

I'll chime in that I see typing used pretty consistently in the deep learning space for a few years now, still not widely accepted but I'd say it's beyond the bleeding edge currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation and tutorials enhancement New feature or request maint Maintenance refactor testing
Projects
None yet
Development

No branches or pull requests

3 participants