Skip to content

Conversation

@XXXXRT666
Copy link
Contributor

Proposed changes

  1. Functions lose precise type hints after transformation. For example, mx.compile only annotates its input and output as Callable, so the original function signature and return types are not preserved in the type system.
  2. Errors occur during the stub gen.
截屏2026-01-16 22 51 04

Type Hints After This PR:

截屏2026-01-16 20 23 34 截屏2026-01-16 20 23 09

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@XXXXRT666
Copy link
Contributor Author

XXXXRT666 commented Jan 16, 2026

Also, python setup.py generate_stubs no longer works, despite being mentioned here.

@zcbenz
Copy link
Collaborator

zcbenz commented Jan 18, 2026

Also, python setup.py generate_stubs no longer works, despite being mentioned here.

Thanks for noticing this, the stubs generation is now part of standard build command after #2949. Can you remove that in document?

extdir = ext_fullpath.parent.parent.resolve()
build_temp = Path(self.build_temp) / ext.name
env = os.environ.copy()
env["PYTHONPATH"] += f":{extdir}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this actually fixes the problem you saw, the exact path has already been passed in the stubgen target:

# Run stubgen -m mlx.core -i python -p _stub_patterns.txt -o python/mlx
RECURSIVE
MODULE
"mlx.core"
PYTHON_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/.."

Can you share the exact command that you used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the command is pip install git+https://github.com/ml-explore/mlx.git -vv and pip install -vv git+https://github.com/XXXXRT666/mlx.git@type-fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CMAKE_CURRENT_SOURCE_DIR = ~/mlx/python/src in my environment, but mlx.core is generated in ~/mlx/build/lib.macosx-11.0-arm64-cpython-310/mlx/core.cpython-310-darwin.so

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the information! Can you check if #3009 fixes the error for you?

@XXXXRT666
Copy link
Contributor Author

Thanks for noticing this, the stubs generation is now part of standard build command after #2949. Can you remove that in document?

I didn't found it in the repo, maybe it's has been modified

@zcbenz
Copy link
Collaborator

zcbenz commented Jan 18, 2026

I didn't found it in the repo, maybe it's has been modified

Sorry my bad, it was already removed in #2949, the website has not been updated yet.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants