Skip to content

Discussion: Enforcing Type Annotations and Run Time Typechecking  #1212

@cobordism

Description

@cobordism

1: Enable Typechecking in CI
We have recently begun adding type hints to our code.
However we currently don't check whether the type hints are correct, nor whether they are followed.
There are python type checkers such as mypy and I wish to suggest that we enable typechecking as part of our CI.
http://mypy-lang.org/ (alternative: https://github.com/google/pytype)

2: Automatically check types of function arguments
Another feature that has been cropping up in our code is a bunch of functions called _typecheck_inputs() that do nothing else than check the types of the variables passed to a function as arguments and give an error if the type is not the one expected.

This seems to me to be a wasteful repeat of effort.
There are ways to enforce at runtime that types passed to a function conform to the type hints. (examples: pydantic, pytypes, enforce).
https://github.com/RussBaz/enforce

I suggest we use one of those libraries instead of writing a separate _typecheck_inputs for every class and every function that only serves to redo what the type hints already provide.

3: Discuss
see below ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAdditions and improvements in general

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions