Skip to content

Tracking issue: Type hints #39

@patrick-rivos

Description

@patrick-rivos

Type hints are very helpful when reading/refactoring/debugging code. They can help show issues without running the code, and highlight edge cases before they're ever executed.

Notes:
Q: Why wrap imports in an if TYPE_CHECKING: statement?
A: Otherwise, we get circular dependencies. Since types aren't actually used at runtime, imports can be safely gated so they're only included when type checking.

Q: Why not annotate return types?
A: The derived return types include things like None, which people are often tempted to omit when typing a function. Allowing MyPy to derive the types on its own ensures we are being honest and get warned when a function's output does not match our expectations.

Q: How do you determine the type to annotate with?
A: I use existing comments, search the codebase for call sites, and print(type(x)) when I'm really lost. It's a best guess, so I may need to update some types as more of the codebase is annotated.

Directories to add type hints to:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions