Your (magic) example code works great! I initially thought it belonged in the class definition for the content type's interface but, in fact, it belongs outside of any class definition.
But I could not get it to work with lead image behaviour. It would result in this error. I don't know why ILeadImage would be different.
when reaching the line
fieldsets = ILeadImage.getTaggedValue(FIELDSETS_KEY)
The way I found that worked was to override the two lead image classes with my own behaviours.py file:
# -*- coding: utf-8 -*-
from plone.app.contenttypes import _
from plone.autoform.interfaces import IFormFieldProvider
from plone.app.contenttypes.behaviors.leadimage import ILeadImage
from plone.dexterity.interfaces import IDexterityContent
from plone.supermodel import model
from zope.component import adapter
from zope.interface import implementer
from zope.interface import provider
def __init__(self, context):
self.context = context
and then using that behaviour in the content type XML definition instead.