Commit Graph

1 Commits

Author SHA1 Message Date
Julien Schueller c3983ffabb [Python] Fix metaclass conflict under -builtin
The SwigPyObjectType metaclass and SwigPyStaticVar type created via
PyType_FromSpec in the heap types path of builtin.swg were allocated as
distinct heap type instances in each compiled module's copy of the
TypeOnce functions. When a class inherited from types defined in
different SWIG extension modules -- such as a director class from
module A and a non-director class from module B -- PyType_FromSpecWithBases
detected incompatible metaclasses and raised:

  TypeError: metaclass conflict

Both TypeOnce functions now check the shared runtime data module for an
existing instance before creating a new one, so all modules share a
single metaclass. This regression was introduced when SWIG_HEAPTYPES
was enabled by default (SWIG 4.4) and only manifests on Python 3.12+.

Fixes #3315.

Assisted-by: opencode (deepseek-v4-flash)
2026-07-22 16:54:04 +02:00