Typing Support in PyPhysim¶
PyPhysim has an increasing support for static typing checking.
Ideally everything in PyPhysim should be type checked without errors by mypy and any new code should ideally have typing information as well.
Note
There are other type checkers that can be used, such as pytype (from Google) or pyre (from Facebook)
Some useful information:¶
Covariance, Contravariance, and Invariance — The Ultimate Python Guide
Accepting any derived class: If the number of subclasses is fixed, just create a Union with all of them. If it is not and you truly want “any subclass of Base”, then try “Generic[Base]” as the argument type.
FadingGenerator = TypeVar('FadingGenerator',
bound=FadingSampleGenerator)
Inspecting the type of variables: Use
reveal_type(expr)
to see the type ofexpr
. It only works in mypy and you get aNameError
if you try to run code with it in Python.