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 type annotations #994

Open
jwodder opened this issue Nov 7, 2023 · 1 comment
Open

Add type annotations #994

jwodder opened this issue Nov 7, 2023 · 1 comment
Labels
category: proposal proposed enhancements or new features priority: medium non-critical problem and/or affecting only a small set of users
Milestone

Comments

@jwodder
Copy link

jwodder commented Nov 7, 2023

Running mypy on code that uses the latest version of hdmf fails with the error message "module is installed, but missing library stubs or py.typed marker". Please add type annotations to this project and include a py.typed file in the package to indicate typing support to mypy.

@oruebel
Copy link
Contributor

oruebel commented Nov 7, 2023

Thanks for the issue. Having support for type hints will be useful.

Just to provide a bit more context on this issue, because there are few factors that make this a bit more complicate beyond adding type hints to existing functions:

  • HDMF as an API can automatically generate classes from data schema at runtime. I.e., the class generator would need to add type hints to the dynamically generated classes. See https://github.com/hdmf-dev/hdmf/blob/dev/src/hdmf/build/classgenerator.py
  • HDMF added type checking before type hints existed in Python. HDMF defines the docval decorator that is used to decorate functions to define what the input parameters should be, e.g., types, shape, etc. docval uses this information to check types at runtime as well as to generate docstrings for the functions. I.e., we would need to modify docval to also generate type hints.
    def docval(*validator, **options): # noqa: C901
  • Since type hints are not enforced backward compatibility may be Ok, but once you would run with mypy it may get more tricky, as the type-hints generated by docval and the classgenerator would have to match in behavior. This means unit and integration testing will likely be a significant task.

Maybe there is a more incremental approach to get to what you are suggesting, i.e., maybe have type hints for some parts. I have not used mypy yet, but as far as I understand it it does not require that everything has type hints, but it will enforce type hints if they exist.

@oruebel oruebel added this to the Future milestone Nov 7, 2023
@oruebel oruebel added category: proposal proposed enhancements or new features priority: medium non-critical problem and/or affecting only a small set of users labels Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: proposal proposed enhancements or new features priority: medium non-critical problem and/or affecting only a small set of users
Projects
None yet
Development

No branches or pull requests

2 participants