-
Notifications
You must be signed in to change notification settings - Fork 14
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
Expose Array not CoreArray (round 2) #128
Conversation
Could maybe just have ChunkedArray = TypeVar("ChunkedArray", bound=CoreArray) # either Array or CoreArray
def rechunk(x: ChunkedArray, chunks, ...) -> ChunkedArray:
return type(x)(name, target, spec, plan) but it doesn't guarantee that we get back |
Is the problem trying to satisfy mypy? It seems that the runtime types are all I wonder if it would help to move the |
The problem was that I was unconvinced that this
was actually true. So I was thinking about how to design the classes in such a way that this was always true. Adding type hints was just to help me work out if this was true or not. However I've just realised I was being thrown off by the fact that I think I'm now happier that I'm no longer going to randomly find my xarray object is wrapping a
Maybe - *(except blockwise because dask's API choice is weird - see note in code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the repr
s - this would definitely be confusing! (I had tried some isinstance tests to convince myself the right types were being returned before.)
This almost ready to go in - just a few naming things in the comments.
Great - fixed all those things. |
Follow on from #124.
I'm trying to type the return values so that mypy can verify for me that the correct type is being returned.
I've successfully typed the array creation functions module, but when I got to the ops module I became confused as to how the class design was supposed to work.
You have
How do you want this to work? Your private subclass is defining public API here. Typing wise this requires that we make
rechunk
pass types through unchanged, soCoreArray.rechunk
returnsCoreArray
andArray.rechunk
returnsArray
. This seems not helpful for ensuring that.rechunk
as seen by the user always returns anArray
.I've used
rechunk
as an example here but I think you have a similar typing problem for many of the functions inops.py
, and one of themap_*
functions returning aCoreArray
is ultimately what's causingfrom_array
to return aCoreArray
(i.e. the specific bug I reported in #123).Is there some obvious way of rewriting this that would ensure we get the correct type back in the public API?