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 details)

Uploaded Python 3

File details

Details for the file refined-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: refined-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.10

File hashes

Hashes for refined-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 041a70eaed411000a0e0eacfe5dbd454c81b311fdfe2e63b7f7d4378bed3810b
MD5 e496860553b81ba1fddd0eb2d939b5f2
BLAKE2b-256 5781e780fd7ff1cbd016bf7899ce033806d3c5fac7f9ac9a6cfcc47880957353

See more details on using hashes here.

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