https://github.com/espetro/refined
Refinement types for Python
https://github.com/espetro/refined
hacktoberfest python python3 refinement-types type-hints
Last synced: 3 months ago
JSON representation
Refinement types for Python
- Host: GitHub
- URL: https://github.com/espetro/refined
- Owner: espetro
- License: mit
- Created: 2021-09-23T21:50:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-04T10:06:00.000Z (over 4 years ago)
- Last Synced: 2025-09-20T05:26:13.854Z (9 months ago)
- Topics: hacktoberfest, python, python3, refinement-types, type-hints
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
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`:
```python
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][docs] for more details.
## Installation
`refined` is available for Python 3.7+:
```shell
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][contributing].
## Acknowledgements
This library is a port of [fthomas' `refined`][scala] Scala library, which, in turn, is a port of
[Nikita Volkov's `refined`][haskell] Haskell library.
[docs]: https://github.com/espetro/refined/wiki
[contributing]: https://github.com/espetro/refined/blob/master/CONTRIBUTING.md
[pep593]: https://www.python.org/dev/peps/pep-0593/
[pep647]: https://www.python.org/dev/peps/pep-0647/
[haskell]: http://nikita-volkov.github.io/refined
[scala]: https://github.com/fthomas/refined