Skip to content
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

Proposal: Support mypy --strict #746

Closed
wangkuiyi opened this issue Feb 26, 2024 · 3 comments
Closed

Proposal: Support mypy --strict #746

wangkuiyi opened this issue Feb 26, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@wangkuiyi
Copy link

I want to use mypy --strict to check my code that depends on MLX. However, the stub generated by pybind11-stubgen at https://github.com/ml-explore/mlx/blob/3b661b73943c8b91d45bdf55da670e8cb308c2a8/setup.py#L137C26-L137C42 does not include accurate type annotation.

In the file ~/miniforge3/envs/mlx-medusa-plus/lib/python3.10/site-packages/mlx/core/__init__.pyi, I have the following signature of mx.repeat:

def repeat(*args, **kwargs):

However, mypy --strict would expect something like the following:

repeat(array: array, repeats: int, axis: Optional[int] = None, *, stream: Union[None, Stream, Device] = None) -> array

I noticed that the help function could reveal accurate type annotations. The run of help(mx.repeat) gave me the following:

repeat(...) method of builtins.PyCapsule instance
    repeat(array: array, repeats: int, axis: Optional[int] = None, *, stream: Union[None, Stream, Device] = None) -> array

Where does help get the information from? Could pybind11-stubgen make use of such information to output accurately annotated functions? Thanks!

@awni awni added the enhancement New feature or request label Feb 26, 2024
@wangkuiyi
Copy link
Author

Hmm. Should I post this proposal to https://github.com/sizmailov/pybind11-stubgen instead?

@awni
Copy link
Member

awni commented Aug 10, 2024

Since we switched to nanobind, the stubs in site-packages/mlx/core/__init__.pyi should have the right type information.

There is also an open issue (#1240) about getting complete typing info for MLX python packages, there are a few annotations missing here and there. I will leave that issue open and close this one as a dup / partially resolved.

@awni awni closed this as completed Aug 10, 2024
@jbcoe
Copy link

jbcoe commented Aug 22, 2024

I'm not seeing site-packages/mlx/core/__init__.pyi in my pip or conda installs of mlx. What do I need to do to get type stubs?

I added #1345 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants