duneanalytics / dune-client

A framework for interacting with Dune Analytics' officially supported API service
Apache License 2.0
85 stars 22 forks source link

Add skip_empty as decorator #45

Open bh2smith opened 1 year ago

bh2smith commented 1 year ago
    this actually works perfectly for python >= 3.10
    # Decorator to skip write on empty data sets.
    # TODO - this cool decorator only works for python >= 3.10
    # @staticmethod
    def _skip_empty(write_like: WriteLikeSignature) -> WriteLikeSignature:
        def wrapper(
            self: FileIO, data: List[DuneRecord], name: str, ftype: FileType
        ) -> None:
            if len(data) == 0:
                logger.info(f"Nothing to write to {name}... skipping")
                return
            write_like(self, data, name, ftype)

        return wrapper

Unfortunately it fails for any earlier version with

 TypeError: 'staticmethod' object is not callable

Here is an issue about it:

https://bugs.python.org/issue43682

Originally posted by @bh2smith in https://github.com/cowprotocol/dune-client/issues/37#issuecomment-1319901120