sip: Conditionally wrapping a virtual method?

Scott Talbert swt at techie.net
Thu Apr 2 16:21:58 BST 2026


Hi,

I'm trying to wrap a C++ class in wxPython that has a virtual method that 
is conditionally defined.  Very simplified, it looks like this:

class wxWindow
{
     public:
         ...other methods...
#if wxUSE_ACCESSIBILITY
         virtual wxAccessible* CreateAccessible() { return nullptr; }
#endif
}

It seems like the sip way of doing this would be to use a feature flag and 
guard this method with %If in the .sip file.  However, wxPython's build 
process pre-generates all the .cpp code as part of the sdist build 
process, so the generated .cpp code is used on all platforms, where 
wxUSE_ACCESSIBILITY is both defined and not.

Is there any way to solve this with sip using a cpp compile time flag? 
If I include the method unconditionally the .sip file, it fails to compile 
on platforms where wxUSE_ACCESSIBILITY is not defined because the method 
is flagged with SIP_OVERRIDE and it doesn't override anything on those 
platforms.

Thanks,
Scott


More information about the PyQt mailing list