-
Notifications
You must be signed in to change notification settings - Fork 31
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
too soon for py.typed? #486
Comments
Thanks for the report. I usually release code into the void and never hear anything back. So it's nice to know someone discovered something after a release, even if it's a bug. Oops. Type checking with The type error you found seems to be caused by def __add__(self, other: Self) -> Self:
return super().__add__(other) It still complains inside that method with the same error: Can users silence I will create a branch working on resolving some of these type issues. Perhaps you can then test it with some of your code and see if it complains relentlessly still? |
Interestingly, when I run
|
I also told mypy not to worry about [[tool.mypy.overrides]]
module = [
"numba.*",
]
ignore_missing_imports = true I agree that it's sad if I don't know of a way to be selective about disabling this sort of warning except by doing it on each individual instance. I have rather a small amount of code and it turned out that all the warnings that I was getting are in the end derived from this single issue. So additional testing with my code isn't going to be very valuable: either this one problem is sorted or it isn't! For much the same reason, you probably shouldn't rush to do anything in particular on my account. My code is pretty much done, in the end it's of very little consequence to me whether the warnings go away or not. Would be very reasonable to wait and see if anyone else shows up with views, or with better ideas. |
Alright. Thanks again for reporting. This is the kind of feedback I'm looking for. I'm going to work on getting the source code to appease |
We're seeing this issue, too, with mypy v1.4.1. I think it is with |
Would you mind providing an example snippet of code and the |
import numpy as np
from galois import GF2
a: GF2 = GF2([0, 1, 0])
b: GF2 = GF2([1, 0, 1])
c: GF2 = np.vstack((a, b))
# mypy output referencing the line above:
# error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "GF2") [assignment]
# but this assertion holds:
assert isinstance(c, GF2) |
Thanks, I remember seeing this when OP first raised this issue. I'm not sure how to resolve that. NumPy controls the return type signature from |
I'm not quite sure either, but using |
Instead of using from typing import cast
import galois
x = galois.GF2([1, 0, 1])
y = galois.GF2([1, 1, 0])
z = x + y
z = cast(galois.GF2, z) I'm working on a branch right now to appease the type checking for arithmetic operations. |
@amirebrahimi would you mind testing #510 and see if it silences most of your issues (wrt to arithmetic operations)? Let me know if I missed any dunder arithmetic methods. Thanks. |
is there a reason for not having annotated the type of any of the |
I suppose I can annotate them as |
I'd assume that the valid operations were more restricted than that? eg wouldn't it be nice if the typechecker warned about |
Yes, that would be better. I'll add that tomorrow. |
def __add__(self, other: Self) -> Self:
return super().__add__(other)
# Multiply is different since integers are treated as scalar multiplication
def __mul__(self, other: int | npt.NDArray | Self) -> Self:
return super().__mul__(other) Here is a small example: import numpy as np
from typing_extensions import reveal_type
import galois
GF = galois.GF(7)
x = GF([1, 0, 1])
y = GF([1, 2, 3])
# y = np.array([1, 2, 3], dtype=float)
z1 = x + y
reveal_type(z1)
z2 = x - y
reveal_type(z2)
z3 = x * y
reveal_type(z3)
z4 = x / y
reveal_type(z4)
z5 = x // y
reveal_type(z5)
z6 = x @ y
reveal_type(z6)
z7 = x % y
reveal_type(z7) When
When
For every case (except for multiplication) a regular Note, if I annotate as Any thoughts or ideas would be appreciated. |
Tried this branch locally with our project and it seems to handle the arithmetic operations mypy issues we were seeing. |
I'd be curious to see what you get if you print out
One thought is to leave it as |
The code currently does this. Running the example with I think I may have to leave the annotation as |
interesting. I have a theory but it is untested so likely wrong I speculate that what mypy is doing is first trying If that's right then
Continuing down this speculative path, I wonder if galois can add an overload for the |
@dimbleby your suspicion was exactly correct. The solution I'm targeting is this: def __add__(self, other: npt.NDArray) -> Self:
return super().__add__(other) It checks for crazy Let me know if either of you have strong feelings. Otherwise, I'll merge #510 soon. |
sounds like a sensible solution to me |
Improved array arithmetic type annotations released in v0.3.7. |
I'm all in favour of typechecking in python and turn it on almost always. So in principle I love the inclusion of
py.typed
in the latest release of this library.However, it seems that the type annotations that are being exported are somewhat incomplete / incorrect. I'm getting quite a lot of warnings that I think I simply can't do anything about. (Well I guess I can
cast()
, but it gets tedious pretty quickly.)The main example that I hit boils down to this:
where, even having given the typechecker as much help as I can there:
because there is no suitable overload on
FieldArray.__add__
Trying to typecheck this project itself, I get
Certainly it's not a requirement to fix all of those before publishing
py.typed
- users of the library could not care less whether your internals typecheck, the API is all that matters. However this is perhaps a hint that the annotations aren't in such good shape just yet.Conscious of showing up only with complaints: I'd like to add that I've really enjoyed using this library! While I've only been using it for some unimportant puzzle-solving, it has saved me a lot of trouble by implementing absolutely loads of useful stuff that I really wouldn't have wanted to struggle over myself. Thank you.
The text was updated successfully, but these errors were encountered: