google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
7.85k stars 786 forks source link

Python Types are missing :( #1292

Closed Artur-Galstyan closed 8 months ago

Artur-Galstyan commented 9 months ago

Is your feature request related to a problem? Please describe. Pyright LSP cannot find the MjData, MjModel etc. types 😢

Describe the solution you'd like A potential solution could be adding python stubs, like amujoco.pyi file or something?

image

FYI: I was checking out Brax when I noticed this

kevinzakka commented 8 months ago

Hi @Artur-Galstyan, I was able to use pybind11-stubgen and point Visual Code to the generated stubs to get type hints.

pip install pybind11-stubgen
pybind11-stubgen mujoco -o ~/typings/  # Installs mujoco stubs dir in $HOME/typings/

Now in visual code, I added the following to my settings.json:

"python.languageServer": "Pylance",
"python.analysis.stubPath": "~/typings",

and the result:

Screenshot 2024-01-02 at 3 01 56 PM

It's not perfect but I think it generates hints for a good chunk of the API. Hope that helps!