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
Release history Release notifications | RSS feed
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.