Fix remaining mypy errors for issue #1282 (PR1)#1387
Conversation
Clear strict mypy with full follow-imports across 20 files: hamiltonians, transforms, resource estimates, and circuit generators. Generator functions now return Iterator[cirq.OP_TREE]; add ase.* to mypy optional-dep overrides.
There was a problem hiding this comment.
Code Review
This pull request focuses on improving type safety and static analysis compliance across the codebase. Key changes include updating return types from cirq.OP_TREE to Iterator[cirq.OP_TREE], adding type annotations, introducing explicit type casts, and resolving various type-checking issues. The review feedback suggests modernizing type hints in isdf.py by using the standard built-in tuple instead of Tuple from the typing module, as the project targets Python 3.9 or newer.
Align isdf, binary_codes, hamiltonian, sparse_integrals, and hartree_fock with modern PEP 585 style already used elsewhere in the batch.
mhucka
left a comment
There was a problem hiding this comment.
This looks great. My one comment is about the use of assert statements for what appears to be run-time value checking.
Address PR review: use if/raise instead of assert for period_cutoff narrowing so checks cannot be disabled with -O.
|
Hey @mhucka, sorry about that, that was my bad, asserts were only for mypy, not real runtime checks. I first swapped for raise ValueError(...), but that wasn’t great either >.< those branches were unreachable because we already default period_cutoff earlier, and ci flagged that. Latest commit pulls default into a small _non_periodic_period_cutoff() helper used in both spots. Same behavior, no assert, no dead raise paths, and mypy is happy. Thanks for the review, and direction. Let me know if I am missing anything. <3 |
Replace unreachable ValueError branches with _non_periodic_period_cutoff so mypy narrowing and coverage both pass without assert or dead raise paths.
Clear strict mypy with full follow-imports across 20 files: hamiltonians, transforms, resource estimates, and circuit generators. Generator functions now return Iterator[cirq.OP_TREE], add ase.* to mypy optional-dep overrides.