/typestring-parser

Parse type strings into typing instances

Primary LanguagePythonMIT LicenseMIT

typestring parser

PyPI Python Version License

Tests Codecov

pre-commit Black

Installation

You can install typestring-parser via pip from PyPI:

$ pip install typestring-parser

Usage

Use the parse function to convert type strings into typing instances:

>>> from typestring_parser import parse
>>>
>>> parse('int')
<class 'int'>
>>> parse('int or str')
typing.Union[int, str]
>>> parse('list of str or str')
typing.Union[typing.List[str], str]
>>> parse('list of (int, str)')
typing.List[typing.Tuple[int, str]]