pvv


Namepvv JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/mianfg/pvv
SummaryMinimal Python decorator to enforce type validation from type hints
upload_time2024-02-23 13:52:00
maintainer
docs_urlNone
authormianfg
requires_python>=3.8,<4.0
licenseMIT
keywords typing validator decorator validate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pvv

Minimal Python decorator to enforce type validation from type hints

## Installation

This library has been created to have zero dependencies, and work with native Python. Use your favorite package manager to install `pvv` from PyPI.

```
pip install pvv
```

## Usage

There are two ways to use the `validate` decorator from `pvv`:

### Validate all parameters

Just use the decorator. A `TypeError` will be raised if the function is called with parameters of incorrect type.

> [!NOTE]
> `pvv` will check if the given parameters to a function are instances of the class annotated as a parameter. If one parameter has no type hints, it will be ignored in the validation.

> [!WARNING]
> `pvv` will only work with type hints that can be used with class and instance checks.

```python
from pvv import validate

@validate
def function(a: str, b: int, c):
    pass
```

```
>>> function("a", 3, 2)
>>> function(c=2, a="a", b=2)
>>> function(3, "a", 2)
TypeError: Incorrect type of function arguments: 'a' must be of type 'str', 'b' must be of type 'int'
```

### Validate some parameters

```python
from pvv import validate

@validate('a', 'c')
def function(a: str, b: int, c: bool | None):
    pass
```

```
>>> function("a", 3, True)
>>> function(3, "b", 0)
TypeError: Incorrect type of function arguments: 'a' must be of type 'str', 'c' must be of type 'bool | None'
```

### An important note

The parameters of the `validate` decorator must all be of type `str`, otherwise a `ValidatorError` will be raised:

```
>>> @validate('a', 1)
... def func(*args, **kwargs):
...     pass
pvv.exceptions.ValidatorError: All arguments of decorator must be of type 'str'
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mianfg/pvv",
    "name": "pvv",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "typing,validator,decorator,validate",
    "author": "mianfg",
    "author_email": "hello@mianfg.me",
    "download_url": "https://files.pythonhosted.org/packages/24/e3/49dd959e7b6c36aa945f621778df8eb93ea874ee80b1b1a8cef78cf6150a/pvv-1.0.0.tar.gz",
    "platform": null,
    "description": "# pvv\n\nMinimal Python decorator to enforce type validation from type hints\n\n## Installation\n\nThis library has been created to have zero dependencies, and work with native Python. Use your favorite package manager to install `pvv` from PyPI.\n\n```\npip install pvv\n```\n\n## Usage\n\nThere are two ways to use the `validate` decorator from `pvv`:\n\n### Validate all parameters\n\nJust use the decorator. A `TypeError` will be raised if the function is called with parameters of incorrect type.\n\n> [!NOTE]\n> `pvv` will check if the given parameters to a function are instances of the class annotated as a parameter. If one parameter has no type hints, it will be ignored in the validation.\n\n> [!WARNING]\n> `pvv` will only work with type hints that can be used with class and instance checks.\n\n```python\nfrom pvv import validate\n\n@validate\ndef function(a: str, b: int, c):\n    pass\n```\n\n```\n>>> function(\"a\", 3, 2)\n>>> function(c=2, a=\"a\", b=2)\n>>> function(3, \"a\", 2)\nTypeError: Incorrect type of function arguments: 'a' must be of type 'str', 'b' must be of type 'int'\n```\n\n### Validate some parameters\n\n```python\nfrom pvv import validate\n\n@validate('a', 'c')\ndef function(a: str, b: int, c: bool | None):\n    pass\n```\n\n```\n>>> function(\"a\", 3, True)\n>>> function(3, \"b\", 0)\nTypeError: Incorrect type of function arguments: 'a' must be of type 'str', 'c' must be of type 'bool | None'\n```\n\n### An important note\n\nThe parameters of the `validate` decorator must all be of type `str`, otherwise a `ValidatorError` will be raised:\n\n```\n>>> @validate('a', 1)\n... def func(*args, **kwargs):\n...     pass\npvv.exceptions.ValidatorError: All arguments of decorator must be of type 'str'\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Minimal Python decorator to enforce type validation from type hints",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/mianfg/pvv/README.md",
        "Homepage": "https://github.com/mianfg/pvv",
        "Repository": "https://github.com/mianfg/pvv"
    },
    "split_keywords": [
        "typing",
        "validator",
        "decorator",
        "validate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "030a43fb498e5887532a6072ce25ffc5122133ba0e73689a6fdcb9d7140fc057",
                "md5": "355ee0b7881adc96e463a5b97eb5f8fa",
                "sha256": "4ecdb152c770aa4799f3242cfd5f4f26529aee028f5b3b835629f06fc8f9ce18"
            },
            "downloads": -1,
            "filename": "pvv-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "355ee0b7881adc96e463a5b97eb5f8fa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 4474,
            "upload_time": "2024-02-23T13:51:58",
            "upload_time_iso_8601": "2024-02-23T13:51:58.721493Z",
            "url": "https://files.pythonhosted.org/packages/03/0a/43fb498e5887532a6072ce25ffc5122133ba0e73689a6fdcb9d7140fc057/pvv-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "24e349dd959e7b6c36aa945f621778df8eb93ea874ee80b1b1a8cef78cf6150a",
                "md5": "54a5d47b5add3b82e3229d9cbcc19f9e",
                "sha256": "8f19c8eba7943fb170eb217ed143514b86a444f3a000295b8a385f6b2d11b8e6"
            },
            "downloads": -1,
            "filename": "pvv-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "54a5d47b5add3b82e3229d9cbcc19f9e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 3907,
            "upload_time": "2024-02-23T13:52:00",
            "upload_time_iso_8601": "2024-02-23T13:52:00.067167Z",
            "url": "https://files.pythonhosted.org/packages/24/e3/49dd959e7b6c36aa945f621778df8eb93ea874ee80b1b1a8cef78cf6150a/pvv-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 13:52:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mianfg",
    "github_project": "pvv",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pvv"
}
        
Elapsed time: 0.19290s