Skip to content

ENH: Support for type hints #444

@Gui-FernandesBR

Description

@Gui-FernandesBR

Is your feature request related to a problem? Please describe.

Type hints were a great addition of Python 3.5 (https://docs.python.org/3/library/typing.html), and it has been improved in the latest python 3.12 version (https://docs.python.org/3/whatsnew/3.12.html). Here are some points to consider:

  • Type hints improve code readability as it makes clear what are the expected values.
  • Enhances static type checking (mypy) to prevent potential errors before execution.
  • IDEs can use these type hints and this can extremely help you when coding.
  • It's easier to review a code when you know exactly the expected types of each argument (we add docstrings for this same reason).
  • All of these provide a better development experience

Describe the solution you'd like

  • There are some solutions on the market that would allow us to automatically generate the type annotations for all the functions, for example, https://github.com/Instagram/MonkeyType
  • Also, mypy could be used to check the annotations as a linter.
  • We should implement type hints in every single function or method. This would be a long process, so I'd say we should introduce this gradually, maybe opening PRs class by class to allow better .
  • Ideally, every new function added to the code should have type hints, ensuring we achieve a good support for type hints.

Additional context

  • Discussion needed here.
  • Type hints do not ensure you're code is free of errors, so it is not a "pill of safety" for users. That's why I think this could benefit devs more than users.
  • For a simplified introduction to type hints, see PEP 483

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsDocs and examples relatedEnhancementNew feature or request, including adjustments in current codes

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions