compas-dev / compas_fab

Robotic fabrication package for the COMPAS Framework.
https://compas.dev/compas_fab/
MIT License
108 stars 32 forks source link

Introduce type hint for type checking #416

Open yck011522 opened 2 months ago

yck011522 commented 2 months ago

Feature Request

As a [developer / user], I want [auto type checking] so that [coding is easier].

Details

I intend to add type hint to functions in a IronPython / Py2 compatible style as described in this very old file. Yes Py2 is old. But unfortunately to make things compatible, it is what it is.

https://github.com/Sumindar/mypy/blob/95ab92015853fbdd3c83b081c470df92e8ca95c4/docs/source/cheat_sheet.rst

The main idea is to add a # type: line immediately before docstring.

    @property
    def attached_tools(self):
        # type: () -> dict[str, Tool]
        """Maps planning group to the tool attached to it."""
        return self._attached_tools

I have been using this style for a while in my own repo. IronPython does not complain, Sphinx does not complain, PyLance in VS code grabs the type hint perfectly and enables certain autocomplete. I believe CoPilot uses this info too to make better suggestions.

I will probably start with the main classes like Robot and Tool.