Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Python type hints with SWIG

The fact that python 3.5+ supports type hints has a great use case when generating wrappers, for instance through SWIG.

Having type hints when working with a large C++ API would make for a much improved experience, since your IDE / linter can perform compile time type checking.

How does one generate type hints with SWIG?

like image 527
Jelle Avatar asked Jan 04 '16 09:01

Jelle


1 Answers

The swig autodoc feature, can give you this, at least in simple cases.

Adding %feature("autodoc", "1") to your SWIG interface code, will generate things like:

def function_name(*args, **kwargs):
    """function_name(int x, int y, Foo foo=None, Bar bar=None) -> bool"""
    ...

See http://www.swig.org/Doc3.0/SWIGDocumentation.html#Python_nn67

like image 70
Bubz0 Avatar answered Oct 03 '22 01:10

Bubz0