Skip to main content

Refinement type hints for Python

Project description

refined: refinement type hints in Python

refined is a Python 3 library that leverages the gradual type system in Python to constrain types by one or multiple predicates. In short, you can ensure that the following script won't raise an IndexError:

from refined import refined, NonEmptyList
from typing import Generator

@refined
def head_with_tail_generator(ls: NonEmptyList[int]) -> (int, Generator[int]):
    return ls[0], (_ for _ in ls[1:])


if __name__ == '__main__':
    head, tail = head_with_tail_generator([])  # this call raises a RefinementTypeException
    print(head)
    [print(_) for _ in tail]

Help

See documentation for more details.

Installation

refined is available for Python 3.7+:

pip install -U refined

Contributing

For guidance on setting up a development environment and how to make a contribution to refined, see Contributing to refined.

Acknowledgements

This library is a port of fthomas' refined Scala library, which, in turn, is a port of Nikita Volkov's refined Haskell library.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

refined-0.0.1-py3-none-any.whl (9.7 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