Skip to content

MAINT: Array API 2024.12 typing nits #156

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

Merged
merged 6 commits into from
Mar 17, 2025

Conversation

crusaderky
Copy link
Contributor

No description provided.

@crusaderky
Copy link
Contributor Author

@lucascolley ready for review and merge

@@ -385,6 +385,9 @@ def isclose(
) -> Array: # numpydoc ignore=PR01,RT01
"""See docstring in array_api_extra._delegation."""
a, b = asarrays(a, b, xp=xp)
if TYPE_CHECKING: # Hack around pyright bug # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the pyright bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given

def f(x: Array | complex) -> Array: ...

x: Array | complex
x = f(x)

when you reach the end of the snippet, mypy correctly understands that x can only be Array, whereas pyright still believes it could be complex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so is it about reusing variable names? Is there an upstream issue we can link to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the upstream answer, what would you like to do here? Use different variable names? Keep the current workarounds but remove the FIXME?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced Array with a fully fledged Protocol. As it would vastly enlarge the scope of this PR, I instead opened a follow-up that reverts these three hacks: #159

Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @crusaderky !

@lucascolley lucascolley merged commit 2f7b4d9 into data-apis:main Mar 17, 2025
10 checks passed
@crusaderky crusaderky deleted the 2024_12_types branch March 17, 2025 15:29
NeilGirdhar pushed a commit to NeilGirdhar/array-api-extra that referenced this pull request Apr 2, 2025
* MAINT: Array API 2024.12 typing nits

* update docstrings

* Update src/array_api_extra/_lib/_utils/_helpers.py

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>

* Add xref to pyright bug

---------

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance general maintenance static typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants