You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type hints improve code readability and error detection, and make it easier (particularly for new contributors) to follow the structure & flow of data through large projects like PyBaMM.
Static type checkers such as MyPy/Pyright can be added at a later date (see #3489) and allow for gradual annotation of a codebase, so we don't need to add hints to the entire project at once.
As part of developing a solution to #3397 I added type hints to the bulk of the expression tree; this later turned out to be unneeded for serialisation but as they are useful more generally I figured they could be added via this issue instead.
The text was updated successfully, but these errors were encountered:
Moving/starting the discussion on the pros + cons of adding mypy/some form of static typing to here rather than on the PR (#3578 (comment)).
My general thought is that formally adding type hints to the codebase without some sort of check that this is being done consistently with existing hints risks making the code less, rather than more, readable (incorrect hints can send you down all sorts of rabbit holes). That said, using mypy to enforce type safety can quickly spiral into a cascade of issues that will need to be fixed, and in some cases making python code pass a static type checker can actually make the code less readable (although that may be down more to personal opinion).
My suggestion is to add mypy to the CI purely to provide informative messages to developers about potential mistakes in type hints, but not enforce it. Gradually adding typing to the codebase can be done slowly over time as various sections are edited.
Description
Type hints improve code readability and error detection, and make it easier (particularly for new contributors) to follow the structure & flow of data through large projects like PyBaMM.
Static type checkers such as MyPy/Pyright can be added at a later date (see #3489) and allow for gradual annotation of a codebase, so we don't need to add hints to the entire project at once.
As part of developing a solution to #3397 I added type hints to the bulk of the expression tree; this later turned out to be unneeded for serialisation but as they are useful more generally I figured they could be added via this issue instead.
The text was updated successfully, but these errors were encountered: