[WIP] Mypy errors - how to fix them #446
vhirtham
announced in
Guidelines
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
[WIP] List of mypy errors and how to fix them:
general
Most of the mypy errors are easy to fix. A list of the ones we have already encountered can be found below. You will also find a proposed fix. If you get an error that is not listed below, please add it to the list and write down what caused the error and how to fix it. A good starting point to figure out some fixes that aren't listed below is this page of the official documentation
Also keep in mind, that some error messages might be false alarms or that the reported piece of code intentionally breaks the rules. If this is the case, just add
# type: ignore
or# type: ignore[ERROR_CODE]
to silence the warning. You can also attach a comment to clarify why the warning gets ignored (if it fits):... # type: ignore[ERROR_CODE] # COMMENT
Running mypy
It is pretty simple. If you have not done it, install mypy:
Then execute it in the WelDX root directory (don't overlook the
.
):List of errors and fixes
category [assignment]
This error occurs if an assignment to a variable assigns a different type than the variable contained before. Redefinitions are allowed to some degree because we set the corresponding configuration value, but it can still occur in some cases.
One case where this happens is that a class sets an internal variable to
None
and assigns the desired value/type in a different function. The easiest fix here is to simply add a type-hint at the variables definition:var: TYPE = None
.category [has-type]
As the message states, the type of a variable can not be determined. The fix is obviously adding a type hint
category [misc]
This error occurred when a static class function used a variable defined in the class scope using
ClassName.variable
. This can be solved by addingClassVar
as type-hint to the corresponding variable.Beta Was this translation helpful? Give feedback.
All reactions