uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Python: empty struct Record produces empty class

Open itrumper opened this issue 1 year ago • 0 comments

Similar to #1781, but for Python. Given the following Rust struct

#[derive(uniffi::Record)]
pub struct MyEmptyRecord {}

Will produce:

class MyEmptyRecord:

    @typing.no_type_check
    def __init__(self, ):

    def __str__(self):
        return "MyEmptyRecord()".format()

    def __eq__(self, other):
        return True

class _UniffiConverterTypeMyEmptyRecord(_UniffiConverterRustBuffer):
    @staticmethod
    def read(buf):
        return MyEmptyRecord(
        )

    @staticmethod
    def write(value, buf):

This produces the warning, "Expected indented block" in the __init__ method, as well as later in the code due to the empty write method. To fix this, the keyword pass should be added where appropriate:

class MyEmptyRecord:
    pass

    @typing.no_type_check
    def __init__(self, ):
        pass

    def __str__(self):
        return "MyEmptyRecord()".format()

    def __eq__(self, other):
        return True

class _UniffiConverterTypeMyEmptyRecord(_UniffiConverterRustBuffer):
    @staticmethod
    def read(buf):
        return MyEmptyRecord(
        )

    @staticmethod
    def write(value, buf):
        pass

itrumper avatar Mar 03 '24 22:03 itrumper