Repository: boto/boto3
File: boto3/resources/base.py (Python)

Code before:


class ResourceMeta(object):
    """
    An object containing metadata about a resource.
    """
    def __init__(self, service_name, identifiers=None, client=None,
                 data=None):
        #: (``string``) The service name, e.g. 's3'
        self.service_name = service_name
        #: (``list``) List of identifier names
        self.identifiers = identifiers or []
        #: (:py:class:`~botocore.client.BaseClient`) Low-level Botocore client
        self.client = client
        #: (``dict``) Loaded resource data attributes
        self.data = data

    def __eq__(self, other):
        # Two metas are equal if their components are all equal
        return self.service_name == other.service_name and \
               self.identifiers == other.identifiers and \
               self.client == other.client and \
               self.data == other.data

    def copy(self):
        """
        Create a copy of this metadata object.
        """
        return ResourceMeta(self.service_name, identifiers=self.identifiers,
                            client=self.client, data=self.data)


class ServiceResource(object):
    """
    A base class for resources.

    :type client: botocore.client
    :param client: A low-level Botocore client instance
    """

    meta = None
    """
    Stores metadata about this resource instance, such as the
    ``service_name``, the low-level ``client`` and any cached ``data``
    from when the instance was hydrated. For example::

        # Get a low-level client from a resource instance
        client = resource.meta.client
        response = client.operation(Param='foo')

        # Print the resource instance's service short name

Review comment (suggestion):
This will require updating the eq everytime we add a new value to this class.  Can we use something like `__dict__` instead? Or anything else to avoid having to update this method.


Code after:


class ResourceMeta(object):
    """
    An object containing metadata about a resource.
    """
    def __init__(self, service_name, identifiers=None, client=None,
                 data=None):
        #: (``string``) The service name, e.g. 's3'
        self.service_name = service_name

        if identifiers is None:
            identifiers = []
        #: (``list``) List of identifier names
        self.identifiers = identifiers

        #: (:py:class:`~botocore.client.BaseClient`) Low-level Botocore client
        self.client = client
        #: (``dict``) Loaded resource data attributes
        self.data = data

    def __repr__(self):
        return 'ResourceMeta(\'{0}\', identifiers={1})'.format(
            self.service_name, self.identifiers)

    def __eq__(self, other):
        # Two metas are equal if their components are all equal
        if other.__class__.__name__ != self.__class__.__name__:
            return False

        return self.__dict__ == other.__dict__

    def copy(self):
        """
        Create a copy of this metadata object.
        """
        params = self.__dict__.copy()
        service_name = params.pop('service_name')
        return ResourceMeta(service_name, **params)


class ServiceResource(object):
    """
    A base class for resources.

    :type client: botocore.client
    :param client: A low-level Botocore client instance
    """

    meta = None
    """