Jelle
Jelle

Reputation: 705

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?

Upvotes: 8

Views: 841

Answers (1)

Bubz0
Bubz0

Reputation: 472

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

Upvotes: 2

Related Questions