Example #1
0
 def __iter__(self):
     """
     Generated by @autodict.
     Implements the __iter__ method from collections.Iterable by relying on vars(self)
     PLUS the super dictionary
     """
     return chain(iterate_on_vars(self),
                  (o for o in super(cls, self).__iter__() if o not in iterate_on_vars(self)))
Example #2
0
 def __repr__(self):
     """
     Generated by @autorepr. Relies on the list of vars() and "getattr" (object) for the value.
     """
     return '%s(**{%s})' % (self.__class__.__name__, ', '.join(
         '%r: %r' % (k, getattr(self, k))
         for k in iterate_on_vars(self)))
 def __eq__(self, other):
     """
     Generated by @autoeq. Relies on the list of vars()  and "getattr" (object) for the value.
     """
     for att_name in iterate_on_vars(self):
         if getattr(self, att_name) != getattr(other, att_name):
             return False
     return True
 def __iter__(self):
     """
     Generated by @autodict. Relying on a filtered vars(self) for the keys iterable
     """
     for att_name in iterate_on_vars(self):
         # filter based on the name (include/exclude + private/public)
         if is_attr_selected(att_name, include=include, exclude=exclude) and \
                 (not public_fields_only or not att_name.startswith(private_name_prefix)):
             # use that name
             yield att_name
    def _vars_iterator(self):
        """
        Filters the vars(self) according to include/exclude/public_fields_only

        :param self:
        :return:
        """
        for att_name in iterate_on_vars(self):
            # filter based on the name (include/exclude + private/public)
            if is_attr_selected(att_name, include=include, exclude=exclude) and \
                    (not public_fields_only or not att_name.startswith(private_name_prefix)):
                # use it
                yield att_name
Example #6
0
 def __iter__(self):
     """
     Generated by @autodict.
     Implements the __iter__ method from collections.Iterable by relying on a filtered vars(self)
     :param self:
     :return:
     """
     myattrs = tuple(att_name for att_name in iterate_on_vars(self))
     for att_name in chain(myattrs, (o for o in super(cls, self).__iter__() if o not in myattrs)):
         # filter based on the name (include/exclude + private/public)
         if is_attr_selected(att_name, include=include, exclude=exclude) and \
                 (not public_fields_only or not att_name.startswith(private_name_prefix)):
             # use that name
             yield att_name
 def __iter__(self):
     """
     Generated by @autodict. Relies on vars(self) to return the iterable of dict keys.
     """
     return iter(iterate_on_vars(self))