Skip to main content

A small library used to obtain types for various builtin iterators.

Project description

IterTypes Library

Code Style: Black Imports: isort PRs welcome

This library has some useful types and functions used to get types of iterables. Whilst iterable types were purposely avoided by the types library, iterables offer unique types which could sometimes be useful to obtain.

Getting started

Start by importing the module:

import itertypes

There are various functions which follow the naming convention is[type]iterator.

itertypes.isstringiterator(iter("string"))
>>> True

dictionary = {1: 2, 3: 4}
iteration = iter(dictionary.items())
itertypes.isdictitemiterator(iteration)
>>> True

There's also the itertypes.isiterator function where it checks if the given object is iterable or not.

my_variable = 5
itertypes.isiterable(my_variable)
>>> False

my_variable = ['a', 'b', 'c', 'd']
all([itertypes.isiterable(my_variable), itertypes.islistiterator(iter(my_variable))])
>>> True

Finally, there's various types which resolve to iterable types. These types can be used with isinstance, or with the equality operator and the type function.

byte = bytearray()
isinstance(iter(byte), itertypes.BytearrayIteratorType)
>>> True

iterable = iter({1: 2, 3: 4}.values())
isinstance(iterable, itertypes.DictValueIteratorType)
>>> True

Installation

Install through pip.

python -m pip install itertypes

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

itertypes-1.6.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

itertypes-1.6.1-py3-none-any.whl (6.8 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