-
Notifications
You must be signed in to change notification settings - Fork 123
Description
I'd like to open a discussion about whether bilby should adopt type hints, which have been part of the standard Python language since version 3.5.
Motivation
Type hints help in the following ways:
- Improve code readability, where inputs and outputs are made explicit
- Enable better static analysis, so problems can be caught before runtime
- Auto-completion and documentation with IDEs
I've recently been using type hints a lot in my own personal workflow, and I have found that they significantly improve the quality of my code, as well as the development experience. I feel adding type-hint support to bilby would improve the package.
Practical considerations
Since bilby is a large and mature codebase, a full retrofit of type hints may not be practical in the short term. However, I think a gradual adoption strategy could work well. For instance, we could encourage contributors to include type hints in new pull requests and add them to the core interfaces and functionality.
In my own experience, it is typically sufficient to add type hints to
- Function arguments and returns
- Class attributes and methods
- Iterables when they are initialised, for example,
my_dict: dict[str, float] = {}
and then the linter is able to infer the rest of the types.
I'd be interested to know others' thoughts on this.