A separate typing package? #863
Replies: 5 comments 12 replies
-
This sounds like a great idea. I'm going to ping @ntessore, who's been thinking about this as well. I appreciate having a single source of truth and if the consensus is to have that be the narrative docs, that sounds good to me. Some thoughts: Such a package would presumably define
IMO this would not be in import array_api as api
def cos(x: api.Array, ...) -> api.Array:
xp = x.__array_namespace__()
return xp.cos(x) A few years back I wrote an example library that defined the Protocols and the "universal" functions: https://github.com/nstarman/array_api |
Beta Was this translation helpful? Give feedback.
-
In addition to the above matters, I suppose that the stub package should manually maintain only the classes that a TypeVar would frequently bound ( Typing functions as |
Beta Was this translation helpful? Give feedback.
-
As a very happy adopter of an Array API typing spec, should one come to exist, here's my take on the questions you raise:
Fully agreed.
As a user I would prefer a separate repo, if only to illustrate the distinction between the actual standard, the strict implementation, the compatibility layer, and the typing implementation.
I think that would defeat the purpose. It's easy to test that my library works with numpy (use numpy in testing). It's hard to verify my library works with any compliant array package.
I'm not sure what that means, exactly, but you might want to pick one of the type checkers and verify that a test suite of annotations passes without complaints.
I would very much hope for a stand-alone package that users of my library don't even have to worry about, unless we are in a |
Beta Was this translation helpful? Give feedback.
-
@nstarman just to split this to a separate thread;
There are two similar efforts here. Xarray has implemented something similar for standard arrays wrapped by Xarray: pydata/xarray#9776. There is also https://github.com/data-apis/array-api-extra, for “universal” functions which are not in the standard. I suppose I don’t see the need for the kind of library you suggest. Is the main idea to avoid consumers having to call |
Beta Was this translation helpful? Give feedback.
-
I was planning on building this myself within And for what it's worth; in jorenham/optype#25 I explain how you could go about typing the "untypeable" dtypes and devices. |
Beta Was this translation helpful? Give feedback.
-
jumping off from #857 (comment) @asmeurer
For various reasons discussed in the linked issue, it seems like this repo may not be the ideal location for the development of static typing for the standard. One proposed idea is to create a new package to house type stubs, which could be used by array libraries to check their compliance, and be used to type libraries which consume array API standard arrays.
One idea which seems to have agreement:
Otherwise, does a separate repo sound like a good idea? Or would it fit into one of the existing
array-api-*
repos? If we want to do this, how should we go about it?Also quoting some higher-level questions from @jorenham:
ping @betatim @rgommers @34j @BvB93 @nstarman @vnmabus @pmeier @TomNicholas
Beta Was this translation helpful? Give feedback.
All reactions