Search code examples
mypydrake

Mypy raises syntax error with pydrake stub


When I try to run mypy in my project that has PyDrake as a depencency I get: venv/lib/python3.9/site-packages/pydrake/common/eigen_geometry.pyi:30: error: invalid syntax

The line in questions is: def cast[AutoDiffXd](self, *args, **kwargs) -> Any: .... I'm assuming this has something to do with PyDrake's custom templating system. How can I make MyPy and PyDrake play nice?

Environment Info

  • OS: Ubuntu 20.04
  • Python version: 3.9.16
  • MyPy version: 0.991
  • Drake version: 1.11.0

Solution

  • As of the current version of Drake (v1.12.0), we unfortunately do not support Mypy. The purpose of the *.pyi files as of today is solely to enable VSCode suggestion auto-complete.

    We didn't have a central issue tracking this, so I've filed a new one. Hopefully we can remove the syntax errors down the road.

    The only work-around I know of for today is to delete the *.pyi files if you use Mypy.