Skip to content

TYP: add pyrefly#695

Merged
lucascolley merged 6 commits into
data-apis:mainfrom
lucascolley:pyrefly
Apr 19, 2026
Merged

TYP: add pyrefly#695
lucascolley merged 6 commits into
data-apis:mainfrom
lucascolley:pyrefly

Conversation

@lucascolley
Copy link
Copy Markdown
Member

@jorenham could I possibly interest you to review?

closes gh-694

Comment thread src/array_api_extra/_lib/_lazy.py
Comment thread tests/test_lazy.py
Comment on lines -222 to +225
ctx: contextlib.AbstractContextManager[object]
ctx: (
contextlib.AbstractContextManager[object]
| contextlib.AbstractContextManager[None]
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

pyrefly is not happy for contextlib.nullcontext() to fall under contextlib.AbstractContextManager[object]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds like a bug in Pyrefly, because the first typar of AbstractContextManager is supposed to be covariant: https://github.com/python/typeshed/blob/eec9fe9aa9ce87df8987de5c1401f743e179378a/stdlib/contextlib.pyi#L48

Do you want to report it or should I?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Go for it if you're happy to!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread vendor_tests/_array_api_compat_vendor.py Outdated
Comment thread vendor_tests/test_vendor.py
Comment on lines 38 to +40
assert is_array_api_obj(x)
assert is_array_api_strict_namespace(xp)
x = cast(Array, x)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

otherwise x stays narrowed by TypeGuard[_ArrayApiObj], where:

Argument type is partially unknown
  Argument corresponds to parameter "x" in function "is_cupy_array"
  Argument type is "ndarray[tuple[Any, ...], dtype[Any]] | Unknown | Array | SupportsArrayNamespace[Any]

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]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
metas: list[Array] = [arg._meta for arg in array_args] # pylint: disable=protected-access # pyright: ignore[reportAttributeAccessIssue] # pyrefly: ignore[missing-attribute]
# pyrefly: ignore[missing-attribute]
metas: list[Array] = [arg._meta for arg in array_args] # pylint: disable=protected-access # pyright: ignore[reportAttributeAccessIssue]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member Author

@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.

I guess I'll merge this if it seems alright @jorenham ?

@lucascolley lucascolley merged commit a068126 into data-apis:main Apr 19, 2026
11 checks passed
@lucascolley lucascolley deleted the pyrefly branch April 19, 2026 21:11
@lucascolley
Copy link
Copy Markdown
Member Author

thanks Joren

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TYP: adopt pyrefly

2 participants