decohints


Namedecohints JSON
Version 1.0.9 PyPI version JSON
download
home_pagehttps://github.com/gri-gus/decohints
SummaryA decorator for decorators that allows you to see the parameters of a decorated function when using it in PyCharm.
upload_time2023-04-03 08:33:12
maintainer
docs_urlNone
authorGrigoriy Gusev
requires_python>=3.5
licenseApache Software License
keywords python decorator deco decohints hints decor decohint python-decorator helper util
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
    <a>
        <img src="https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/cover.png" alt="decohints">
    </a>
</p>

<p align="center">
    <a href="https://pypi.org/project/decohints" target="_blank">
        <img src="https://img.shields.io/pypi/v/decohints" alt="PyPI">
    </a>
    <a href="https://pypi.org/project/decohints" target="_blank">
        <img src="https://static.pepy.tech/badge/decohints" alt="PyPI">
    </a>
    <a href="https://opensource.org/licenses/Apache-2.0" target="_blank">
        <img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="PyPI">
    </a>
</p>

# decohints

<a href="https://github.com/gri-gus/decohints/blob/main/README.ru.md" target="_blank"><b>🇷🇺 Версия на русском</b></a>

A decorator for decorators that allows you to see the parameters of a decorated function when using it in PyCharm.

**PyPi**: https://pypi.org/project/decohints/

## Reasons for creation

Below is an example of a decorator with parameters without the use of `decohints`:

```python
from functools import wraps


def decorator_with_params(aa=None, bb=None, cc=None):
    def _decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            try:
                result = func(*args, **kwargs)
            except Exception:
                print("Error")
                return
            return result

        return wrapper

    return _decorator


@decorator_with_params()
def test(a: int, b: int) -> int:
    return a + b
```

If you type below `test()` in PyCharm and wait, it will show decorator wrapper parameter hints as `test` function
parameter hints:

<img width="150" height="105" src="https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/1.png" alt="test() (*args, **kwargs)">

This is not convenient and can confuse developers, which is why this library was made.

## Installation

```shell
pip install decohints
```

## Usage

> ✅ Works with all kinds of decorators \
> ⚠️ If your decorator is already wrapped in another decorator, then `decohints` should be on top

To use, you need to follow two simple steps:

1. Import the `decohints` decorator from the `decohints` library:

```python
from decohints import decohints
```

2. Wrap your decorator with a `decohints` decorator:

```python
@decohints
def your_decorator():
    ...
```

The following is an example of a decorator with parameters, with using `decohints`:

```python
from functools import wraps

from decohints import decohints


@decohints
def decorator_with_params(aa=None, bb=None, cc=None):
    def _decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            try:
                result = func(*args, **kwargs)
            except Exception:
                print("Error")
                return
            return result

        return wrapper

    return _decorator


@decorator_with_params()
def test(a: int, b: int) -> int:
    return a + b
```

If you type below `test()` in PyCharm and wait, it will show `test` function parameter hints:

<img width="150" height="105" src="https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/2.png" alt="test() (a: int, b: int)">

> ❕Examples of use with decorator class, class decorators, and more are found at here:
<a href="https://github.com/gri-gus/decohints/tree/main/examples/decohints" target="_blank"><b>click</b></a>

## Alternatives

### Specifying the type of wrapper

> ✅ Works with all kinds of decorator functions

Specifying the type `wrapper: func` will have the same behavior as using `decohints`.

Example:

```python
from functools import wraps


def decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
        except Exception:
            print("Error")
            return
        return result

    wrapper: func
    return wrapper


@decorator
def test(a: int, b: int) -> int:
    return a + b
```

If you type below `test()` in PyCharm and wait, it will show `test` function parameter hints:

<img width="150" height="105" src="https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/2.png" alt="test() (a: int, b: int)">

### Specifying an output type in a decorator with parameters

> ❗️This method only works in decorator functions with parameters

If you specify the `Callable` type from the `typing` module for the result of the decorator with parameters, then the
behavior will be the same as using `decohints`.

Example:

```python
from functools import wraps
from typing import Callable


def decorator_with_params(aa=None, bb=None, cc=None) -> Callable:
    def _decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            try:
                result = func(*args, **kwargs)
            except Exception:
                print("Error")
                return
            return result

        return wrapper

    return _decorator


@decorator_with_params()
def test(a: int, b: int) -> int:
    return a + b
```

If you type below `test()` in PyCharm and wait, it will show `test` function parameter hints:

<img width="150" height="105" src="https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/2.png" alt="test() (a: int, b: int)">



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gri-gus/decohints",
    "name": "decohints",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "python,decorator,deco,decohints,hints,decor,decohint,python-decorator,helper,util",
    "author": "Grigoriy Gusev",
    "author_email": "thegrigus@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/56/f0/791ba6f965487a81c3b494a5c14354f99bc57418d79ab903e72da4b0d4d5/decohints-1.0.9.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n    <a>\n        <img src=\"https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/cover.png\" alt=\"decohints\">\n    </a>\n</p>\n\n<p align=\"center\">\n    <a href=\"https://pypi.org/project/decohints\" target=\"_blank\">\n        <img src=\"https://img.shields.io/pypi/v/decohints\" alt=\"PyPI\">\n    </a>\n    <a href=\"https://pypi.org/project/decohints\" target=\"_blank\">\n        <img src=\"https://static.pepy.tech/badge/decohints\" alt=\"PyPI\">\n    </a>\n    <a href=\"https://opensource.org/licenses/Apache-2.0\" target=\"_blank\">\n        <img src=\"https://img.shields.io/badge/License-Apache_2.0-blue.svg\" alt=\"PyPI\">\n    </a>\n</p>\n\n# decohints\n\n<a href=\"https://github.com/gri-gus/decohints/blob/main/README.ru.md\" target=\"_blank\"><b>\ud83c\uddf7\ud83c\uddfa \u0412\u0435\u0440\u0441\u0438\u044f \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c</b></a>\n\nA decorator for decorators that allows you to see the parameters of a decorated function when using it in PyCharm.\n\n**PyPi**: https://pypi.org/project/decohints/\n\n## Reasons for creation\n\nBelow is an example of a decorator with parameters without the use of `decohints`:\n\n```python\nfrom functools import wraps\n\n\ndef decorator_with_params(aa=None, bb=None, cc=None):\n    def _decorator(func):\n        @wraps(func)\n        def wrapper(*args, **kwargs):\n            try:\n                result = func(*args, **kwargs)\n            except Exception:\n                print(\"Error\")\n                return\n            return result\n\n        return wrapper\n\n    return _decorator\n\n\n@decorator_with_params()\ndef test(a: int, b: int) -> int:\n    return a + b\n```\n\nIf you type below `test()` in PyCharm and wait, it will show decorator wrapper parameter hints as `test` function\nparameter hints:\n\n<img width=\"150\" height=\"105\" src=\"https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/1.png\" alt=\"test() (*args, **kwargs)\">\n\nThis is not convenient and can confuse developers, which is why this library was made.\n\n## Installation\n\n```shell\npip install decohints\n```\n\n## Usage\n\n> \u2705 Works with all kinds of decorators \\\n> \u26a0\ufe0f If your decorator is already wrapped in another decorator, then `decohints` should be on top\n\nTo use, you need to follow two simple steps:\n\n1. Import the `decohints` decorator from the `decohints` library:\n\n```python\nfrom decohints import decohints\n```\n\n2. Wrap your decorator with a `decohints` decorator:\n\n```python\n@decohints\ndef your_decorator():\n    ...\n```\n\nThe following is an example of a decorator with parameters, with using `decohints`:\n\n```python\nfrom functools import wraps\n\nfrom decohints import decohints\n\n\n@decohints\ndef decorator_with_params(aa=None, bb=None, cc=None):\n    def _decorator(func):\n        @wraps(func)\n        def wrapper(*args, **kwargs):\n            try:\n                result = func(*args, **kwargs)\n            except Exception:\n                print(\"Error\")\n                return\n            return result\n\n        return wrapper\n\n    return _decorator\n\n\n@decorator_with_params()\ndef test(a: int, b: int) -> int:\n    return a + b\n```\n\nIf you type below `test()` in PyCharm and wait, it will show `test` function parameter hints:\n\n<img width=\"150\" height=\"105\" src=\"https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/2.png\" alt=\"test() (a: int, b: int)\">\n\n> \u2755Examples of use with decorator class, class decorators, and more are found at here:\n<a href=\"https://github.com/gri-gus/decohints/tree/main/examples/decohints\" target=\"_blank\"><b>click</b></a>\n\n## Alternatives\n\n### Specifying the type of wrapper\n\n> \u2705 Works with all kinds of decorator functions\n\nSpecifying the type `wrapper: func` will have the same behavior as using `decohints`.\n\nExample:\n\n```python\nfrom functools import wraps\n\n\ndef decorator(func):\n    @wraps(func)\n    def wrapper(*args, **kwargs):\n        try:\n            result = func(*args, **kwargs)\n        except Exception:\n            print(\"Error\")\n            return\n        return result\n\n    wrapper: func\n    return wrapper\n\n\n@decorator\ndef test(a: int, b: int) -> int:\n    return a + b\n```\n\nIf you type below `test()` in PyCharm and wait, it will show `test` function parameter hints:\n\n<img width=\"150\" height=\"105\" src=\"https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/2.png\" alt=\"test() (a: int, b: int)\">\n\n### Specifying an output type in a decorator with parameters\n\n> \u2757\ufe0fThis method only works in decorator functions with parameters\n\nIf you specify the `Callable` type from the `typing` module for the result of the decorator with parameters, then the\nbehavior will be the same as using `decohints`.\n\nExample:\n\n```python\nfrom functools import wraps\nfrom typing import Callable\n\n\ndef decorator_with_params(aa=None, bb=None, cc=None) -> Callable:\n    def _decorator(func):\n        @wraps(func)\n        def wrapper(*args, **kwargs):\n            try:\n                result = func(*args, **kwargs)\n            except Exception:\n                print(\"Error\")\n                return\n            return result\n\n        return wrapper\n\n    return _decorator\n\n\n@decorator_with_params()\ndef test(a: int, b: int) -> int:\n    return a + b\n```\n\nIf you type below `test()` in PyCharm and wait, it will show `test` function parameter hints:\n\n<img width=\"150\" height=\"105\" src=\"https://raw.githubusercontent.com/gri-gus/decohints/main/assets/images/2.png\" alt=\"test() (a: int, b: int)\">\n\n\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "A decorator for decorators that allows you to see the parameters of a decorated function when using it in PyCharm.",
    "version": "1.0.9",
    "split_keywords": [
        "python",
        "decorator",
        "deco",
        "decohints",
        "hints",
        "decor",
        "decohint",
        "python-decorator",
        "helper",
        "util"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b7bd4358edcd028eb4313f91d9972d976e81f3dbfb1035a5511f31f73f248b2",
                "md5": "bd331f4e953bcfebaab31d789b29c0d2",
                "sha256": "3007256b1b179ccca9e240ea4117c8b59cd31e32de9129c95bbbb867f320c922"
            },
            "downloads": -1,
            "filename": "decohints-1.0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd331f4e953bcfebaab31d789b29c0d2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 7351,
            "upload_time": "2023-04-03T08:33:10",
            "upload_time_iso_8601": "2023-04-03T08:33:10.195798Z",
            "url": "https://files.pythonhosted.org/packages/9b/7b/d4358edcd028eb4313f91d9972d976e81f3dbfb1035a5511f31f73f248b2/decohints-1.0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56f0791ba6f965487a81c3b494a5c14354f99bc57418d79ab903e72da4b0d4d5",
                "md5": "a9d178a3811347e5e59179f54df7c63b",
                "sha256": "0e066715f003ddef965fce223d1e83bf9102f8bfb5be3e98bc545aef58fca944"
            },
            "downloads": -1,
            "filename": "decohints-1.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "a9d178a3811347e5e59179f54df7c63b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 7074,
            "upload_time": "2023-04-03T08:33:12",
            "upload_time_iso_8601": "2023-04-03T08:33:12.445722Z",
            "url": "https://files.pythonhosted.org/packages/56/f0/791ba6f965487a81c3b494a5c14354f99bc57418d79ab903e72da4b0d4d5/decohints-1.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-03 08:33:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "gri-gus",
    "github_project": "decohints",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "decohints"
}
        
Elapsed time: 0.36663s