Skip to content

StdPairConverter does not support delegation for nested containers #250

@timosachsenberg

Description

@timosachsenberg

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<...>>:

  1. pair is not in names_of_wrapper_classes (it's an STL type)
  2. _has_delegating_converter(tt) returns False because StdPairConverter.supports_delegation() is False
  3. Code falls through to the else branch that relies on Cython's automatic conversion
  4. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions