Skip to content

espetro/refined

Repository files navigation

refined: refinement type hints in Python

Tests Package version

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.