-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Annotation Checker Problems with UFloat #178
Comments
The type checker could realize that this type defines mathematical operations and avoid raising any warning for the first mathematical operation, at least. What warnings are you getting? What type checker are you using? |
This looks like a limitation of PyCharm: there is enough information available (namely that UFloats can be multiplied by something) for not getting a warning. Now, maybe it's possible to help PyCharm by adding type annotations to uncertainties? I would encourage to report this problem to PyCharm and report back here, so as to know what uncertainties could do to help. |
PyCharm also gives what appears to be a much more useful error. "Class 'AffineScalarFunc' does not define '__mul__', so the '*' operator cannot be used on its instances". Also worth noting is that PyCharms type annotations do occasionally mess up eg. with np.atleast_nd on objects or arrays of objects |
Thanks for the details. PyCharm is actually wrong about In [7]: from uncertainties.core import AffineScalarFunc
In [8]: AffineScalarFunc.__mul__
Out[8]: <function uncertainties.core.wrap.<locals>.f_with_affine_output(*args, **kwargs)> The reason is that Now, a solution maybe is to have PyCharm actually import I looked at numeric abstract classes, hoping I could explicitly declare that Now, it would be possible to define a dummy (no-op) What do you think? |
Yep, PyCharms type checker is indeed just missing this. It would be a very large amount of effort to create dummys for all methods but given that type hints can just be left out for code like this probably makes it not a priority in my opinion. |
I am having problems with the type checking with "UFloat" (the "AffineScalarFunc" type)
In the documentation it says the following:
So when using "UFloat" to denote that a variable belongs is a number with uncertainties the type checker flags mathematical operations.
Is this intended behavior?
Should I rather use "ufloat" when doing type annotations and use "UFloat" only for
isinstance(...)
checks?It would be useful if "UFloat" could be used for type annotations.
The text was updated successfully, but these errors were encountered: