/
niceSOFT
/
swig
Обзор
Документация
Войти
/
niceSOFT
/
swig
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Examples/test-suite/python_pyi.i
49 строк
1 KB
William S Fulton
[Python] Fix empty classes and imported bases in .pyi files
05 авг 2026, 01:41
05 авг 2026, 01:41
f06d867
Код
Авторство
О чём код?
%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; }; Unwrapped *make_unwrapped() { return 0; } %}