Skip to content

Add type annotations #2236

@sbliven

Description

@sbliven

I would like to propose introducing type annotations to BioPython.

For those unfamiliar, type annotations are specified by PEP 484 and add static type-checking to python code. Two syntaxes are available; an annotation syntax for python 3 and a type comment syntax which is compatible with python 2 code. For example:

def f(num1, my_float=3.5):
    # type: (int, float) -> float
    return num1 + my_float

The annotations are no-ops at runtime, but allow type checking tools to be run over the code (e.g. as a tox test) to detect type errors. The python community has standardized on the MyPy type checking package for the static analysis.

Code without a type annotation is treated permissively by the type checker, so types can be added incrementally to the project over time.

BioPython could start providing types for some core data structures using the py27 comment syntax. At whatever point BioPython drops 2.7 support (after 2020), development could then switch to using the cleaner annotation syntax.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions