realitix / vulkan

The ultimate Python binding for Vulkan API
Apache License 2.0
505 stars 46 forks source link

class _StrWrap unsupported python2 #14

Closed mackst closed 7 years ago

mackst commented 7 years ago
class _StrWrap():
    """Wrap a FFI Cdata object

    This class is a proxy class which auto-convert FFI string to Python
    string. It must be used only on object containing string data.
    Original CFFI string can always be accessed by prefixing the property with
    an underscore.
    """
    def __init__(self, obj):
        self.obj = obj

    def __setattr__(self, key, value):
        if key == 'obj':
            return super().__setattr__(key, value)

        setattr(self.obj, key, value)

    def __getattr__(self, key):
        try:
            attr = getattr(self.obj, key)
        except AttributeError as origin_exc:
            # Remove the first underscore if exists
            if key.startswith('_'):
                try:
                    return getattr(self.obj, key[1:])
                except AttributeError:
                    raise origin_exc
            raise origin_exc

        return _cstr(attr)

This is not supported on python2

    def __setattr__(self, key, value):
        if key == 'obj':
            return super().__setattr__(key, value)

If you run on python2 will get this error. return super().setattr(key, value) TypeError: super() takes at least 1 argument (0 given) Exception TypeError: "'NoneType' object is not callable" in <bound method HelloTriangleApplication.del of <main.HelloTriangleApplication object at 0x000000000306F888>> ignored

realitix commented 7 years ago

Hello @mackst. Thanks for the report. You are right, I didn't test on Python2 after adding this class.

realitix commented 7 years ago

Fixed here https://github.com/realitix/vulkan/commit/da62f4a2d14fb3fa03fdaa69e4173cdef526a57d

Thanks !