Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue: Type hints #39

Open
5 of 13 tasks
patrick-rivos opened this issue Jun 23, 2023 · 1 comment
Open
5 of 13 tasks

Tracking issue: Type hints #39

patrick-rivos opened this issue Jun 23, 2023 · 1 comment

Comments

@patrick-rivos
Copy link
Contributor

patrick-rivos commented Jun 23, 2023

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:

@rbertran
Copy link
Collaborator

rbertran commented Jul 12, 2023

Base on the discussion we had here, I'd update this issue to add another a couple of items:

  • Run the mypy as a CI step in Travis to perform static type check validation
  • Enable typeguard during the execution of the CI tests to perform dynamic type check validation during tests (ensure we do not affect production code performance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants