microprobe icon indicating copy to clipboard operation
microprobe copied to clipboard

Tracking issue: Type hints

Open patrick-rivos opened this issue 1 year ago • 1 comments

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:

  • [ ] src/microprobe
    • [x] code #38
    • [ ] driver
    • [x] model #48
    • [ ] passes
    • [x] schemas
    • [x] target #42
    • [ ] utils
    • [ ] other files in this dir
  • [ ] targets
    • [x] generic #49
    • [ ] powerpc
    • [ ] riscv

patrick-rivos avatar Jun 23 '23 16:06 patrick-rivos