-
Notifications
You must be signed in to change notification settings - Fork 21
TYP: add pyrefly
#695
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: add pyrefly
#695
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,7 @@ | |||||||
| P = ParamSpec("P") | ||||||||
|
|
||||||||
|
|
||||||||
| @overload | ||||||||
| @overload # pyrefly: ignore[invalid-param-spec] | ||||||||
| def lazy_apply( # type: ignore[valid-type] | ||||||||
| func: Callable[P, Array | ArrayLike], | ||||||||
| *args: Array | complex | None, | ||||||||
|
|
@@ -42,7 +42,7 @@ def lazy_apply( # type: ignore[valid-type] | |||||||
| ) -> Array: ... # numpydoc ignore=GL08 | ||||||||
|
|
||||||||
|
|
||||||||
| @overload | ||||||||
| @overload # pyrefly: ignore[invalid-param-spec] | ||||||||
| def lazy_apply( # type: ignore[valid-type] | ||||||||
| func: Callable[P, Sequence[Array | ArrayLike]], | ||||||||
| *args: Array | complex | None, | ||||||||
|
|
@@ -54,7 +54,7 @@ def lazy_apply( # type: ignore[valid-type] | |||||||
| ) -> tuple[Array, ...]: ... # numpydoc ignore=GL08 | ||||||||
|
|
||||||||
|
|
||||||||
| def lazy_apply( # type: ignore[valid-type] # numpydoc ignore=GL07,SA04 | ||||||||
| def lazy_apply( # type: ignore[valid-type] # pyrefly: ignore[invalid-param-spec] # numpydoc ignore=GL07,SA04 | ||||||||
| func: Callable[P, Array | ArrayLike | Sequence[Array | ArrayLike]], | ||||||||
| *args: Array | complex | None, | ||||||||
| shape: tuple[int | None, ...] | Sequence[tuple[int | None, ...]] | None = None, | ||||||||
|
|
@@ -240,7 +240,7 @@ def lazy_apply( # type: ignore[valid-type] # numpydoc ignore=GL07,SA04 | |||||||
| if is_dask_namespace(xp): | ||||||||
| import dask | ||||||||
|
|
||||||||
| metas: list[Array] = [arg._meta for arg in array_args] # pylint: disable=protected-access # pyright: ignore[reportAttributeAccessIssue] | ||||||||
| metas: list[Array] = [arg._meta for arg in array_args] # pylint: disable=protected-access # pyright: ignore[reportAttributeAccessIssue] # pyrefly: ignore[missing-attribute] | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to avoid long lines, then this should also do the trick I believe:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could do, but tbh I don't mind long lines as long as they are just comments to the machine |
||||||||
| meta_xp = array_namespace(*metas) | ||||||||
|
|
||||||||
| wrapped = dask.delayed( # type: ignore[attr-defined] # pyright: ignore[reportPrivateImportUsage] | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,7 +219,10 @@ def test_lazy_apply_none_shape_in_args(xp: ModuleType, library: Backend): | |
| mxp = np if library is Backend.DASK else xp | ||
| int_type = xp.asarray(0).dtype | ||
|
|
||
| ctx: contextlib.AbstractContextManager[object] | ||
| ctx: ( | ||
| contextlib.AbstractContextManager[object] | ||
| | contextlib.AbstractContextManager[None] | ||
| ) | ||
|
Comment on lines
-222
to
+225
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pyrefly is not happy for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a bug in Pyrefly, because the first typar of Do you want to report it or should I?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go for it if you're happy to!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if library.like(Backend.JAX): | ||
| ctx = pytest.raises(ValueError, match="Output shape must be fully known") | ||
| elif library is Backend.ARRAY_API_STRICTEST: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| """This file is a hook imported by `src/array_api_extra/_lib/_compat.py`.""" | ||
| # pyright: reportUnknownParameterType=false, reportMissingParameterType=false | ||
|
|
||
| from .array_api_compat import * # noqa: F403 | ||
| from types import ModuleType | ||
| from typing import Any | ||
|
|
||
| from .array_api_compat import * # type: ignore[import-not-found] # noqa: F403 | ||
| from .array_api_compat import array_namespace as array_namespace_compat | ||
|
|
||
|
|
||
| # Let unit tests check with `is` that we are picking up the function from this module | ||
| # and not from the original array_api_compat module. | ||
| def array_namespace(*xs, **kwargs): # numpydoc ignore=GL08 | ||
| def array_namespace(*xs: Any | complex | None, **kwargs) -> ModuleType: # pyrefly: ignore[unannotated-parameter] # numpydoc ignore=GL08 | ||
| return array_namespace_compat(*xs, **kwargs) |
|
lucascolley marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,14 @@ | ||
| # pyright: reportAttributeAccessIssue=false | ||
|
|
||
| from typing import Any | ||
| from typing import Any, cast | ||
|
|
||
| import array_api_strict as xp | ||
| from numpy.testing import assert_array_equal | ||
|
|
||
| from vendor_tests.array_api_compat.common._typing import ( # type: ignore[import-not-found] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should be cloning the vendored libraries into place for the static analysis — not sure |
||
| Array, | ||
| ) | ||
|
|
||
|
|
||
| def test_vendor_compat(): | ||
| from ._array_api_compat_vendor import ( # type: ignore[attr-defined] | ||
|
|
@@ -35,6 +39,7 @@ def test_vendor_compat(): | |
| to_device(x, device(x)) | ||
| assert is_array_api_obj(x) | ||
| assert is_array_api_strict_namespace(xp) | ||
| x = cast(Array, x) | ||
|
Comment on lines
40
to
+42
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. otherwise |
||
| assert not is_cupy_array(x) | ||
| assert not is_cupy_namespace(xp) | ||
| assert not is_dask_array(x) | ||
|
|
@@ -53,15 +58,18 @@ def test_vendor_compat(): | |
|
|
||
|
|
||
| def test_vendor_extra(): | ||
| from .array_api_extra import atleast_nd | ||
| from .array_api_extra import atleast_nd # type: ignore[import-not-found] | ||
|
|
||
| x = xp.asarray(1) | ||
| x = cast(Array, x) | ||
| y = atleast_nd(x, ndim=0) | ||
| assert_array_equal(y, x) # pyright: ignore[reportUnknownArgumentType] | ||
| assert_array_equal(y, x) | ||
|
|
||
|
|
||
| def test_vendor_extra_testing(): | ||
| from .array_api_extra.testing import lazy_xp_function | ||
| from .array_api_extra.testing import ( # type: ignore[import-not-found] | ||
| lazy_xp_function, | ||
| ) | ||
|
|
||
| def f(x: Any) -> Any: | ||
| return x | ||
|
|
@@ -71,6 +79,8 @@ def f(x: Any) -> Any: | |
|
|
||
| def test_vendor_extra_uses_vendor_compat(): | ||
| from ._array_api_compat_vendor import array_namespace as n1 | ||
| from .array_api_extra._lib._utils._compat import array_namespace as n2 | ||
| from .array_api_extra._lib._utils._compat import ( # type: ignore[import-not-found] | ||
| array_namespace as n2, | ||
| ) | ||
|
|
||
| assert n1 is n2 | ||
Uh oh!
There was an error while loading. Please reload this page.