Skip to content

Discussion: Add type hint support to bilby #963

Description

@fgittins

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.

Activity

  1. added theissue type on Jun 12, 2025
  2. mj-will commented on Aug 11, 2026

    @mj-will
    Collaborator

    We discussed this on the last dev call in relation to #1110. The consensus was we'd like to add type hints. Given that, I think the next step is to make a plan for how to add them and decide which modules we should priortize. We may also need to set out some guidelines.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions