fix: make numpy.typing import explicit - #46
Merged
domrachev03 merged 4 commits intoAug 23, 2026
Conversation
ArrayLike: TypeAlias = np.typing.ArrayLike | jax.typing.ArrayLike is a module-level expression evaluated at import time. On numpy < 2.0, np.typing only resolves if numpy.typing has been imported earlier; today this happens incidentally via trimesh (a transitive dependency of mujoco-mjx), which imports numpy.typing at startup. Add an explicit import so the alias no longer depends on that side effect — if mujoco-mjx changes its dependencies or import order, this module keeps working.
mjx.kinematics expects mjx Model/Data wrapper types (which expose the .impl attribute), not the raw mujoco.MjModel. Wrap the model with mjx.put_model() before calling kinematics.
jax.Array is not a collections.abc.Sequence, so mypy rejected self.target_q = jnp.zeros(...) against the Sequence-typed setters. The setters already convert via jnp.array(), so accepting jnp.ndarray | Sequence is accurate and keeps list inputs valid.
pytest >= 9 strictly validates filterwarnings as a linelist; the single-string form makes pytest fail at startup. The list form is the standard syntax and is accepted by both pytest 8 and 9.
Contributor
Author
|
I dug into the three failing CI checks and pushed fixes (commits b4c7482, 7239283, d60c179). All were pre-existing issues, unrelated to the one-line
All three checks were verified locally on the same dependency versions CI resolves (mujoco 3.12.0, pytest 9.1.1, jax 0.11.1). |
Member
|
Thank you for addressing them! Looks good to me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #45
Problem
np.typing.XXXis only accessible on numpy < 2.0 ifnumpy.typinghas been explicitly imported earlier. Without a version constraint forcing numpy >= 2, users with numpy 1.x installed can hit:when the annotation is evaluated at import time.
Fix
File:
mjinx/typing.pyfrom __future__ import annotations + import numpy.typing import jax.typing ArrayLike: TypeAlias = np.typing.ArrayLike | jax.typing.ArrayLike(
ArrayLike: TypeAlias = ...is a module-level expression — PEP 563 does not defer it. Today the alias only resolves through an incidental side effect: trimesh, pulled in via mujoco-mjx, importsnumpy.typingat startup. The explicit import removes that hidden reliance.)Verification
from mjinx import typingsucceeds today because trimesh (a transitive dependency via mujoco-mjx) executesimport numpy.typingat import time — line 31'snp.typing.ArrayLikeonly resolves through that side effect.ArrayLikealias no longer depends on trimesh's internals or the import order inside mujoco-mjx — if that transitive chain changes in the future, this module keeps working.