swig/Lib/python
William S Fulton afc39844b4 [Python] Add %pythonstubcode and %pythonstubbegin directives
These are the .pyi stub file equivalents of %pythoncode and %pythonbegin,
for adding Python code to the stub file generated by the -pyi and -pyifile
options. They do nothing unless a stub file is being generated.

%pythonstubcode inserts the code at the point the directive appears,
indenting it into the class body when used inside a class. %pythonstubbegin
inserts the code just after the SWIG banner, before any real code.

The stub file is generated independently of the .py file, so code added with
%pythoncode or %pythonbegin does not appear in it. Classes configured with
%pythonabc use names from collections.abc as generated base classes and
pyabc.i imports this module into the .py file, but a separately generated
stub had no import, leaving its base class unresolved. Add the equivalent
%pythonstubcode block to pyabc.i.

Extend the python_pyi test with a collections.abc base class and blocks
exercising both new directives.

See #3473.

Assisted-by: Claude Code (Opus 5)
2026-08-04 23:41:57 +01:00
..
Makefile.in Complete the Python 2 removal and fix issues found reviewing it 2026-07-06 23:50:31 +01:00
README Python: Add PEP 484 annotations for simple types 2026-03-24 14:56:16 +01:00
argcargv.i argcargv / OOM-protection follow-ups 2026-05-19 21:01:30 +01:00
attribute.i move attribute.i to the typemap library, now is usable from all the languages 2005-10-25 13:20:50 +00:00
boost_shared_ptr.i More move semantics improvements 2022-07-04 11:19:50 +01:00
builtin.swg [Python] Fix metaclass conflict under -builtin 2026-07-22 16:54:04 +02:00
carrays.i carrays.i library modified to use size_t instead of int 2023-10-11 08:23:16 +01:00
ccomplex.i [Python] Only define pytyping typemaps where in typemaps are defined 2026-07-23 17:30:59 +01:00
cmalloc.i more typemaps unification and fixes for valgrind 2005-10-19 10:52:50 +00:00
complex.i more comments and cosmetic fixes 2004-03-23 01:07:45 +00:00
cpointer.i more typemaps unification and fixes for valgrind 2005-10-19 10:52:50 +00:00
cstring.i Perl added to the Unified typemap library, cleaner way to use the library, and 'normalized' macro names 2005-10-24 14:59:05 +00:00
cwstring.i Perl added to the Unified typemap library, cleaner way to use the library, and 'normalized' macro names 2005-10-24 14:59:05 +00:00
director.swg Fix -Wextra-semi warnings (#3372) 2026-03-18 18:53:05 +00:00
director_py_mutex.swg Fix crash when using directors in Python without limited API 2025-01-28 15:11:28 +01:00
exception.i use internal SWIG_exception_fail, let SWIG_exception as in 1.3.27 2006-01-14 21:23:36 +00:00
factory.i add the factory library for UTL 2006-02-22 18:42:20 +00:00
file.i Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
implicit.i securing the call to SWIG_IsOK, which is a macro 2005-12-30 01:14:24 +00:00
pyabc.i [Python] Add %pythonstubcode and %pythonstubbegin directives 2026-08-04 23:41:57 +01:00
pyapi.swg Re-organise some generate Python code for method creation and docstring support 2019-02-10 22:55:16 +00:00
pybackward.swg add more backward comp macros/fragments/methods 2006-01-28 08:59:32 +00:00
pybuffer.i Restore missing testing of python_pybuffer testcase 2025-12-04 06:42:02 +00:00
pyclasses.swg Fix director arguments taking a const ref to the language object type 2026-08-01 16:35:12 +01:00
pycomplex.swg Remove some locator strings in generated code 2024-04-12 08:12:44 +01:00
pycontainer.swg Python: Remove Python 2 compatibility macros 2026-07-06 23:50:31 +01:00
pydocs.swg Cosmetic stray semi-colon removal after %typemap using quotes 2022-08-31 19:40:13 +01:00
pyerrors.swg Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
pyfragments.swg Fix confusion of filenaming in comment 2007-11-19 21:32:01 +00:00
pyhead.swg Python: Remove Python 2 compatibility macros 2026-07-06 23:50:31 +01:00
pyinit.swg Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
pyiterators.swg Complete the Python 2 removal and fix issues found reviewing it 2026-07-06 23:50:31 +01:00
pymacros.swg add more backward comp macros/fragments/methods 2006-01-28 08:48:48 +00:00
pyopers.swg Python: Drop operators compatibility 2026-07-06 23:50:30 +01:00
pyprimtypes.swg Python: Avoid compatibility macros 2026-07-06 23:50:30 +01:00
pyrun.swg Python: Remove Python 2 compatibility macros 2026-07-06 23:50:31 +01:00
pyruntime.swg Cosmetic tweaks defining __cplusplus 2025-11-27 19:21:08 +00:00
pystdcommon.swg Python: Avoid compatibility macros 2026-07-06 23:50:30 +01:00
pystrings.swg Pass SWIG_FromCharPtrAndSize and friends on to the C compiler 2026-07-31 00:10:40 +01:00
python.swg [Python] Only define pytyping typemaps where in typemaps are defined 2026-07-23 17:30:59 +01:00
pythonkw.swg Python: Update keywords 2026-07-06 23:50:31 +01:00
pythreads.swg [python] Prevent a potential multithreading crash 2022-10-21 14:26:41 -07:00
pytypemaps.swg Use the canonical capitalisation of Unified Typemap Library 2026-07-23 17:30:59 +01:00
pytyping.swg [Python] Only define pytyping typemaps where in typemaps are defined 2026-07-23 17:30:59 +01:00
pyuserdir.swg [Python] Add %pythonstubcode and %pythonstubbegin directives 2026-08-04 23:41:57 +01:00
pywstrings.swg [Python] Only define pytyping typemaps where in typemaps are defined 2026-07-23 17:30:59 +01:00
std_alloc.i better support for string and def. args, plus adding allocator + sstream 2004-12-01 01:22:30 +00:00
std_array.i Visual C++ warning fixes 2023-12-30 13:49:40 +00:00
std_auto_ptr.i Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr 2022-09-17 10:23:51 +01:00
std_basic_string.i std_basic_string.i fixes 2018-01-04 07:00:26 +00:00
std_char_traits.i isolate language independent STD/STL/C++ code + more documentation + cleaning 2004-10-10 06:42:15 +00:00
std_common.i Fix STL wrappers to not generate <: digraphs. 2015-12-12 14:05:46 +00:00
std_complex.i [Python] Only define pytyping typemaps where in typemaps are defined 2026-07-23 17:30:59 +01:00
std_container.i isolate language independent STD/STL/C++ code + more documentation + cleaning 2004-10-10 06:42:15 +00:00
std_deque.i Add missing parameter names in STL container wrappers 2019-02-13 22:45:47 +00:00
std_except.i add std_except typemaps to the unified typemap library 2005-10-31 09:43:02 +00:00
std_filesystem.i Add forward class definition for std::filesystem::path class 2024-08-19 18:33:10 +01:00
std_ios.i isolate language independent STD/STL/C++ code + more documentation + cleaning 2004-10-10 06:42:15 +00:00
std_iostream.i better support for string and def. args, plus adding allocator + sstream 2004-12-01 01:22:30 +00:00
std_list.i Add missing parameter names in STL container wrappers 2019-02-13 22:45:47 +00:00
std_map.i Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
std_multimap.i Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
std_multiset.i Remove assign method uses by the removed Python Sequence Protocol 2023-04-26 18:18:15 +01:00
std_pair.i Py_DECREF -> Py_DecRef for stable ABI compliance 2024-03-24 18:12:21 +00:00
std_set.i Remove assign method uses by the removed Python Sequence Protocol 2023-04-26 18:18:15 +01:00
std_shared_ptr.i Add std_shared_ptr.i and document shared_ptr library 2010-06-01 19:03:55 +00:00
std_sstream.i better support for string and def. args, plus adding allocator + sstream 2004-12-01 01:22:30 +00:00
std_streambuf.i better support for string and def. args, plus adding allocator + sstream 2004-12-01 01:22:30 +00:00
std_string.i Python: Map more primitives for PEP 484 annotations 2026-07-23 17:30:59 +01:00
std_string_view.i Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
std_unique_ptr.i Add const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
std_unordered_map.i Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
std_unordered_multimap.i Python: Drop PY_VERSION_HEX<3.5 code 2026-07-06 23:50:30 +01:00
std_unordered_multiset.i Remove assign method uses by the removed Python Sequence Protocol 2023-04-26 18:18:15 +01:00
std_unordered_set.i Remove assign method uses by the removed Python Sequence Protocol 2023-04-26 18:18:15 +01:00
std_vector.i More efficient Python slicing 2016-09-01 23:49:30 +01:00
std_vectora.i isolate language independent STD/STL/C++ code + more documentation + cleaning 2004-10-10 06:42:15 +00:00
std_wios.i allow to use iostream and sstream without wchar support, as pointed by Scott 2005-04-03 03:16:25 +00:00
std_wiostream.i add fragment warning and fixes 2006-01-30 22:22:13 +00:00
std_wsstream.i allow to use iostream and sstream without wchar support, as pointed by Scott 2005-04-03 03:16:25 +00:00
std_wstreambuf.i allow to use iostream and sstream without wchar support, as pointed by Scott 2005-04-03 03:16:25 +00:00
std_wstring.i Python: Map more primitives for PEP 484 annotations 2026-07-23 17:30:59 +01:00
stl.i Create a consistent stl.i library file 2019-02-12 18:46:05 +00:00
swigmove.i Provide SWIGTYPE MOVE typemaps in swigmove.i 2022-09-16 08:36:25 +01:00
typemaps.i Remove deprecated BOTH typemap rule 2023-06-15 15:07:04 +12:00
wchar.i allow to use iostream and sstream without wchar support, as pointed by Scott 2005-04-02 19:06:31 +00:00

README

/* -----------------------------------------------------------------------------
 *
 *  User interfaces: include these ones as needed
 *
 * ----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
 *  Special types and user helpers 
 * ----------------------------------------------------------------------------- */

argcargv.i		Handler for (int argc, char **argv)
attribute.i		Convert a pair of set/get methods into a "native" python attribute
ccomplex.i		C99 complex type
complex.i		C99 or C++ complex type
cstring.i		Various forms of C character string handling
cwstring.i		Various forms of C wchar_t string handling
embed.i			embedding the Python interpreter in something else
file.i			FILE C type
implicit.i		Allow the use of implicit C++ constructors
wchar.i			wchar_t C type

/* -----------------------------------------------------------------------------
 *  C++ STD + STL
 * ----------------------------------------------------------------------------- */

std_alloc.i		allocator 
std_basic_string.i	basic string
std_char_traits.i	char traits
std_complex.i		complex
std_deque.i		deque	
std_except.i		exceptions
std_ios.i		ios
std_iostream.i		istream/ostream
std_list.i		list
std_map.i		map
std_multimap.i		multimap
std_multiset.i		multiset
std_pair.i		pair
std_set.i		set
std_sstream.i		string stream
std_streambuf.i		streambuf
std_string.i		string
std_vector.i		vector
std_wios.i		wios
std_wiostream.i		wistream/wostream
std_wsstream.i		wstring stream
std_wstreambuf.i	wstreambuf
std_wstring.i		wstring



/* -----------------------------------------------------------------------------
/* 
 *  Implementation files: don't look at them unless you are really drunk
 *
 * ----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
 *  Basic files
 * ----------------------------------------------------------------------------- */

python.swg		Main language file, it just includes what is needed.
pyuserdir.swg		User visible directives (%pythonnondynamic, etc)
pymacros.swg		Internal macros used for typemaps
pyfragments.swg		Allow the user to overload the default fragments
pyopers.swg		Python operations (+=, *=, etc)
pythonkw.swg		Python keywords and special names
pyinit.swg		Python Init method

/* -----------------------------------------------------------------------------
 *  The runtime part
 * ----------------------------------------------------------------------------- */

pyruntime.swg		Main runtime file definition
pyapi.swg		SWIG/Python API declarations
pyrun.swg		Python run-time code 

/* -----------------------------------------------------------------------------
 *  Internal typemap specializations
 * ----------------------------------------------------------------------------- */

pyswigtype.swg		SWIGTYPE
pystrings.swg		Char strings (char *)
pywstrings.swg		Wchar Strings (wchar_t *)
pyprimtypes.swg		Primitive types (shot,int,double,etc)
pycomplex.swg		PyComplex and helper for C/C++ complex types
pydocs.swg		Typemaps documentation
pytyping.swg        PEP 484 type hints

/* -----------------------------------------------------------------------------
 *  C++ STD + STL
 * ----------------------------------------------------------------------------- */

pycontainer.swg		python container iterators
std_common.i		general common code for the STD/STL implementation
std_container.i		general common code for the STD/STL containers


/*-----------------------------------------------------------------------------
 *  Backward compatibility and deprecated
 * ----------------------------------------------------------------------------- */

std_vectora.i		vector + allocator (allocators are now supported in STD/STL)
typemaps.i		old in/out typemaps (doesn't need to be included)