Skip to main content

Decorator to convert a class into an iterable.

Project description

Iterable decorator

Create iterable classes using a class decorator.

Values added to an iterable class are sored in the class's self.args attribute as a tuple of whatever type you have provided.

Examples

from iterables import iterable

@iterable
class Items:

    # You can type annotate your iterable like so:
    item: str
    # Note that this has no real effect on the generation of the iterable.

items = Items("Hello", "iterables!")

for item in items:
    print(item)

>>> "Hello"
>>> "iterables!"

You can attach additional methods to an iterable as you would with a dataclass.

from iterables import iterable

@iterable
class Items:
    item: str

    @classmethod
    def from_list(data: list[str]):
        return cls(*data)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iterables-decorator-0.1.1.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

iterables_decorator-0.1.1-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page