Problem
When using std::vector<std::pair<T1, T2>> where T1 or T2 is a wrapped C++ class, Cython fails with:
Cannot convert 'vector[pair[String,AASequence]]' to Python object
Root Cause
StdPairConverter does not override supports_delegation(), so it returns False (the base class default). This means when StdVectorConverter processes vector<pair<...>>:
pair is not in names_of_wrapper_classes (it's an STL type)
_has_delegating_converter(tt) returns False because StdPairConverter.supports_delegation() is False
- Code falls through to the else branch that relies on Cython's automatic conversion
- Cython can't automatically convert
pair<String, AASequence> because AASequence is a wrapped class
Reproduction
# In .pxd file:
libcpp_vector[libcpp_pair[String, AASequence]] getVariantSequences() except + nogil
This generates code that Cython cannot compile.
Proposed Solution
Have StdPairConverter override supports_delegation() to return True:
class StdPairConverter(TypeConverterBase):
# ...
def supports_delegation(self) -> bool:
return True
This would allow StdVectorConverter to delegate to StdPairConverter.output_conversion() which already handles wrapped classes correctly (lines 801-826 in ConversionProvider.py).
Workaround
Currently using # wrap-ignore and implementing the method manually in a Python addon file.
Environment
- autowrap version: 0.26.0 (from pyOpenMS)
- Cython version: 3.x
- Python: 3.10+
Related Code
StdPairConverter (line 661)
StdPairConverter.output_conversion() (line 781) - already handles wrapped classes
StdVectorConverter._has_delegating_converter() check (line 2089)
TypeConverterBase.supports_delegation() default (line 137)
Problem
When using
std::vector<std::pair<T1, T2>>where T1 or T2 is a wrapped C++ class, Cython fails with:Root Cause
StdPairConverterdoes not overridesupports_delegation(), so it returnsFalse(the base class default). This means whenStdVectorConverterprocessesvector<pair<...>>:pairis not innames_of_wrapper_classes(it's an STL type)_has_delegating_converter(tt)returnsFalsebecauseStdPairConverter.supports_delegation()isFalsepair<String, AASequence>becauseAASequenceis a wrapped classReproduction
This generates code that Cython cannot compile.
Proposed Solution
Have
StdPairConverteroverridesupports_delegation()to returnTrue:This would allow
StdVectorConverterto delegate toStdPairConverter.output_conversion()which already handles wrapped classes correctly (lines 801-826 in ConversionProvider.py).Workaround
Currently using
# wrap-ignoreand implementing the method manually in a Python addon file.Environment
Related Code
StdPairConverter(line 661)StdPairConverter.output_conversion()(line 781) - already handles wrapped classesStdVectorConverter._has_delegating_converter()check (line 2089)TypeConverterBase.supports_delegation()default (line 137)