| %module python_pyi | |
| // Tests the -pyi command line option, which generates a .pyi PEP 484 | |
| // stub file. This is primarily meant for -builtin/-fastproxy, where the | |
| // python:annotations feature otherwise has nowhere to attach annotations. | |
| %feature("python:annotations", "typing"); | |
| // A type with no proxy class, to exercise the opaque SWIGTYPE_* wrapper | |
| // class that $pytypename falls back to, which must also be emitted into | |
| // the .pyi stub (not just the .py shadow file) for the annotation below | |
| // to resolve to a real name. | |
| struct Unwrapped; | |
| %typemap(pytyping) Unwrapped * "$pytypename" | |
| %feature("python:abc", "collections.abc.Sized") SizedCollection; | |
| %pythoncode %{ | |
| import collections.abc | |
| %} | |
| %pythonstubcode %{ | |
| import collections.abc | |
| %} | |
| %pythonstubbegin %{ | |
| # Generated by %pythonstubbegin | |
| %} | |
| %inline %{ | |
| struct Unwrapped; | |
| class SizedCollection { | |
| public: | |
| int size() const { return 0; } | |
| }; | |
| class Empty { | |
| private: | |
| Empty(); | |
| }; | |
| class Widget { | |
| public: | |
| Widget(int id): id(id) {} | |
| int getId() const { return id; } | |
| static Widget *create(int id) { return new Widget(id); } | |
| int id; | |
| }; | |
| // An overloaded static method is declared with the catch all parameters, which must be wide enough for the one it hides | |
| class OverloadedWidget : public Widget { | |
| public: | |
| OverloadedWidget(int id): Widget(id) {} | |
| static Widget *create(int id) { return new Widget(id); } | |
| static Widget *create(int id, int extra) { return new Widget(id + extra); } | |
| }; | |
| Unwrapped *make_unwrapped() { return 0; } | |
| %} |