-
Notifications
You must be signed in to change notification settings - Fork 8
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
TYP: type annotations #135
base: main
Are you sure you want to change the base?
Conversation
Can ignore python 3.9, cf #129 |
# Note: indexing was 'str' in <=2024.12 | ||
def meshgrid(*arrays: Array, indexing: str = "xy") -> list[Array]: |
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.
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.
not sure if this is inconsequential enough that I should just go on and define it as Literal here?
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 the PR Guido!
I went through up to _linalg.py
before running out of steam for the week. In general it looks great, my main gripe is about annotations for python scalars:
- several look like global search-and-replace : floordiv,
__gt__
just do not acceptcomplex
- I'm -1 for changing
bool | int | float
into justfloat
.
array_api_strict/_array_object.py
Outdated
@@ -184,7 +193,9 @@ def __array__(self, dtype: None | np.dtype[Any] = None, copy: None | bool = None | |||
# spec in places where it either deviates from or is more strict than | |||
# NumPy behavior | |||
|
|||
def _check_allowed_dtypes(self, other: bool | int | float | Array, dtype_category: str, op: str) -> Array: | |||
def _check_allowed_dtypes( | |||
self, other: Array | complex, dtype_category: str, op: str |
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.
ints, bools and floats are allowed. I get that a float is-a complex but nonetheless. As long as this is for a human reader more than for a linter, let's be more descriptive. Here and elsewhere.
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.
As long as this is for a human reader more than for a linter
I think @jorenham is right that this has a lot of drawbacks. Once you get used to annotations, you know that complex subsumes all of those options. If you want to make things clear for novices, why not use a docstring?
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.
Here's the point though, none of this is for a human reader that isn't pushing a PR to this repo, save for the public functions in _flags.py
!
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.
Sorry, no. If the tooling is not ready, we don't use it until it is. Please roll it back, here and in the -strict PR.
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.
What do you mean by the "the tooling is not ready"? Python typing will probably never alter the definition of these basic types, right?
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.
What do you mean by the "the tooling is not ready"? Python typing will probably never alter the definition of these basic types, right?
That's right.
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.
Good stuff! I left a couple of suggestions; do with it what you want 👌🏻
array_api_strict/_array_object.py
Outdated
@@ -184,7 +193,9 @@ def __array__(self, dtype: None | np.dtype[Any] = None, copy: None | bool = None | |||
# spec in places where it either deviates from or is more strict than | |||
# NumPy behavior | |||
|
|||
def _check_allowed_dtypes(self, other: bool | int | float | Array, dtype_category: str, op: str) -> Array: | |||
def _check_allowed_dtypes( | |||
self, other: Array | complex, dtype_category: str, op: str |
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.
What do you mean by the "the tooling is not ready"? Python typing will probably never alter the definition of these basic types, right?
That's right.
I took the liberty of creating a label for static typing stuff and painted it black because that's how I prefer my coffee (and my metal) |
Co-authored-by: Joren Hammudoglu <[email protected]>
Co-authored-by: Joren Hammudoglu <[email protected]>
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.
Let me record my -1 on bool | int |float
until data-apis/array-api-compat#257 (comment) is done.
Can we please find a minimum common ground that allows us to merge this PR? |
To repeat, my only strong feelings are on
With these two items being there, I'm declaring my expertise on typing to run out, the typing itself being considered mostly harmless; I'm thus dismissing my request for changes and bow out. As long as my boundary conditions are not exceeded, I'm happy with whatever y'all converge on. |
This is ready for final review. |
I believe there should not be any oustanding comments? |
Trying to push things forward hat on:It sounds like both @crusaderky and I would be happy to keep Would merging @crusaderky's 2 PRs disrupt your work at data-apis/array-api-compat#288 @jorenham ?
I haven't read the entirety of all of these threads, but are there any outstanding concerns about consistency apart from the Opinion hat on:For me, there is no significant consistency concern about If the concern is that inconsistency between the spec saying |
array-api-compat
(TYP: Type annotations overhaul, part 1 array-api-compat#257)py.typed
iinfo
andfinfo
would return a numpy dtype instead of a DTypeOut of scope