Closed cjpatton closed 3 months ago
For basic type checks, it would be better form to do assert isinstance(rand, bytes)
. For more complicated types, note that list[int]
in the source turns into just list
at runtime. Thus, we'd have to split up the assertions into, for example, assert isinstance(measurement, list)
and assert all(isinstance(elem, int) for elem in measurement)
.
Which implies that the type would have to define its own type checking method :(
Yeah, at that point I think it would make sense to roll the asserts into the top of each VDAF method.
After #363, mypy
's type checking is now working much better for us. While these type hints aren't checked at runtime, they still provide a good degree of assurance that our code is well-typed (especially with check_untyped_defs = True
). Thus, there is no longer a need for manual runtime type assertions.
While working on #59 we found that the "class factory" pattern we're following for instantiating the
Vdaf
API is not enforceable bymypy
. We still want type enforcement, so we'll do this at runtime instead. We think this will be easier/cleaner if we move away from the hacky class factory pattern to proper, Python-style OOP. E.g.:Then a concrete VDAF would call this method explicitly: