def iter_attribute(iterable_name) -> Union[Iterable, Callable]:
def create_new_class(decorated_class) -> Union[Iterable, Callable]:<EOL><INDENT>"""<STR_LIT>"""<EOL>assert inspect.isclass(decorated_class), '<STR_LIT>'<EOL>assert isinstance(iterable_name, str), '<STR_LIT>'<EOL>decorated_class.iterator_attr_index = <NUM_LIT:0><EOL>def __iter__(instance) -> Iterable:<EOL><INDENT>"""<STR_LIT>"""<EOL>return instance<EOL><DEDENT>def __next__(instance) -> Any:<EOL><INDENT>"""<STR_LIT>"""<EOL>assert hasattr(instance, iterable_name),'<STR_LIT>'.format(iterable_name)<EOL>assert isinstance(getattr(instance, iterable_name), collections.Iterable),'<STR_LIT>'.format(iterable_name, instance.__class__.__name__)<EOL>ind = instance.iterator_attr_index<EOL>while ind < len(getattr(instance, iterable_name)):<EOL><INDENT>val = getattr(instance, iterable_name)[ind]<EOL>instance.iterator_attr_index += <NUM_LIT:1><EOL>return val<EOL><DEDENT>instance.iterator_attr_index = <NUM_LIT:0><EOL>raise StopIteration<EOL><DEDENT>dct = dict(decorated_class.__dict__)<EOL>dct['<STR_LIT>'] = __iter__<EOL>dct['<STR_LIT>'] = __next__<EOL>dct['<STR_LIT>'] = decorated_class.iterator_attr_index<EOL>return type(decorated_class.__name__, (collections.Iterable,), dct)<EOL><DEDENT>return create_new_class<EOL>
Decorator implementing Iterator interface with nicer manner.

    Example
    -------

    @iter_attribute('my_attr'):
    class DecoratedClass:
        ...

    Warning:
    ========

    When using PyCharm or MYPY you'll probably see issues with decorated class not being recognized as Iterator.
    That's an issue which I could not overcome yet, it's probably due to the fact that interpretation of object
    is being done statically rather than dynamically. MYPY checks for definition of methods in class code which
    changes at runtime. Since __iter__ and __next__ are added dynamically MYPY cannot find those
    defined in objects before object of a class is created. Possible workarounds for this issue are:

        1. Define ``dummy`` __iter__ class like:

            @iter_attribute('attr')
            class Test:
                def __init__(self) -> None:
                    self.attr = [1, 2, 3]

                def __iter__(self):
                    pass

        2. After creating object use cast or assert function denoting that particular instance inherits
            from collections.Iterator:

            assert isinstance(my_object, collections.Iterator)


    :param iterable_name: string representing attribute name which has to be iterated
    :return: DecoratedClass with implemented '__iter__' and '__next__' methods.