Improve clarity of simulation setups with typing.override
#1291
Labels
user group
Issue to be worked on in the internal user group.
typing.override
#1291
Python 3.12 introduced the
typing.override
decorator. This allows static type checkers to check whether a child class method/attribute actually overrides the method/attribute of one of the parent classes.Setting up simulations in PorePy requires intensive subclassing of various mixins and overriding method/attributes. Wrongly named method/attributes in the subclasses cause the wrong (i.e., the parent's) methods/attributes to be called. This can happen easily and go unnoticed, but cause unwanted behavior and tedious debugging sessions.
@override
helps by type checking for such errors beforehand.Example
The spelling error in the first method causes the model to run on the wrong domain size:
With the use of
@override
,mypy
catches the errorTo make life easier, in particular for new users, the tutorials could make use of
@override
as a best practice and have some short explanation similar to above.Would be happy to hear some opinions or ideas on this :) If this was already discussed internally and dismissed, let me know.
The text was updated successfully, but these errors were encountered: