NiceDecorator


NameNiceDecorator JSON
Version 1.1.3 PyPI version JSON
download
home_page
SummaryAn easy and nice decorator package
upload_time2023-11-19 09:01:04
maintainer
docs_urlNone
author
requires_python>=3.10, <4
licenseMIT License
keywords decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NiceDecorator

### An easy and nice decorator package

## Use:
### Model
    from NiceDecorator.model import Deco_Timer
    
    decor = Deco_Timer()
    
    @decor
    def f():
        print(1)
    
    a = f()
    print(a)

#### result
    $ python 3.11.4 $
    1
    1.9600032828748226e-05

### Decorator
#### No.1
    from NiceDecorator import decorator
    decor = decorator.Deco_aFunction(wrap=(timecount.time_start_ns, FUNCTION, timecount.time_end_ns))
    @decor
    def f():
        print(1)

    a = f()
    b = f()
    print(a, b)
    

#### result
    $ python 3.11.4 $
    181000 168600

#### No.2
    from NiceDecorator import decorator
    class DECORATOR(decorator.Deco_iFunction):
        def begin(self):
            print("start")
        def end(self):
            print("end")
        def adef(self):
            print("def")
    
    @DECORATOR()
    def g():
        print(2)
    
    g()
    g()
    

#### result
    $ python 3.11.4 $
    def
    start
    2
    end
    start
    2
    end


#### No.3
    from NiceDecorator import decorator
    @decorator.Deco_wFunction
    def decor2(func, *args, **kwargs):
        print("===")
        res = func(*args, **kwargs)
        print("===")
        return res
    
    @decor2
    def h():
        print(3)
    
    h()
    h()

#### result
    $ python 3.11.4 $
    ===
    3
    ===
    ===
    3
    ===

## Tips:
Package NiceDecorator has 5 magic parameters, there are
'func', 'args', 'kwargs', 'res', 'tram'.

The 'func' parameter is used in the function definition section
and is automatically passed in to the decorated function. 
In 'model.Deco_Expand', 'func' is extended to the beginning and end of the function.

The 'args' parameter is used at the beginning of the function
and is automatically passed in as a positional parameter. 

The 'kwargs' parameter is used at the beginning of the function
and automatically passes in keyword parameters.

The 'res' paramter is used at the end of the function
and automatically passes in the function return value. 

The 'tram' parameter is used at the beginning
and end of the function to pass data. 

For more tips, see '__init__.py'.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "NiceDecorator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10, <4",
    "maintainer_email": "",
    "keywords": "decorator",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/ff/e5/05b7d1f185b2a2f2076d49b42630fc16e0366cc808f0ad14b0187e4a9432/NiceDecorator-1.1.3.tar.gz",
    "platform": null,
    "description": "# NiceDecorator\r\n\r\n### An easy and nice decorator package\r\n\r\n## Use:\r\n### Model\r\n    from NiceDecorator.model import Deco_Timer\r\n    \r\n    decor = Deco_Timer()\r\n    \r\n    @decor\r\n    def f():\r\n        print(1)\r\n    \r\n    a = f()\r\n    print(a)\r\n\r\n#### result\r\n    $ python 3.11.4 $\r\n    1\r\n    1.9600032828748226e-05\r\n\r\n### Decorator\r\n#### No.1\r\n    from NiceDecorator import decorator\r\n    decor = decorator.Deco_aFunction(wrap=(timecount.time_start_ns, FUNCTION, timecount.time_end_ns))\r\n    @decor\r\n    def f():\r\n        print(1)\r\n\r\n    a = f()\r\n    b = f()\r\n    print(a, b)\r\n    \r\n\r\n#### result\r\n    $ python 3.11.4 $\r\n    181000 168600\r\n\r\n#### No.2\r\n    from NiceDecorator import decorator\r\n    class DECORATOR(decorator.Deco_iFunction):\r\n        def begin(self):\r\n            print(\"start\")\r\n        def end(self):\r\n            print(\"end\")\r\n        def adef(self):\r\n            print(\"def\")\r\n    \r\n    @DECORATOR()\r\n    def g():\r\n        print(2)\r\n    \r\n    g()\r\n    g()\r\n    \r\n\r\n#### result\r\n    $ python 3.11.4 $\r\n    def\r\n    start\r\n    2\r\n    end\r\n    start\r\n    2\r\n    end\r\n\r\n\r\n#### No.3\r\n    from NiceDecorator import decorator\r\n    @decorator.Deco_wFunction\r\n    def decor2(func, *args, **kwargs):\r\n        print(\"===\")\r\n        res = func(*args, **kwargs)\r\n        print(\"===\")\r\n        return res\r\n    \r\n    @decor2\r\n    def h():\r\n        print(3)\r\n    \r\n    h()\r\n    h()\r\n\r\n#### result\r\n    $ python 3.11.4 $\r\n    ===\r\n    3\r\n    ===\r\n    ===\r\n    3\r\n    ===\r\n\r\n## Tips:\r\nPackage NiceDecorator has 5 magic parameters, there are\r\n'func', 'args', 'kwargs', 'res', 'tram'.\r\n\r\nThe 'func' parameter is used in the function definition section\r\nand is automatically passed in to the decorated function. \r\nIn 'model.Deco_Expand', 'func' is extended to the beginning and end of the function.\r\n\r\nThe 'args' parameter is used at the beginning of the function\r\nand is automatically passed in as a positional parameter. \r\n\r\nThe 'kwargs' parameter is used at the beginning of the function\r\nand automatically passes in keyword parameters.\r\n\r\nThe 'res' paramter is used at the end of the function\r\nand automatically passes in the function return value. \r\n\r\nThe 'tram' parameter is used at the beginning\r\nand end of the function to pass data. \r\n\r\nFor more tips, see '__init__.py'.\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "An easy and nice decorator package",
    "version": "1.1.3",
    "project_urls": null,
    "split_keywords": [
        "decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ffe505b7d1f185b2a2f2076d49b42630fc16e0366cc808f0ad14b0187e4a9432",
                "md5": "0c2ae28fec9635b6836f0e48ea07492f",
                "sha256": "dc49bca001facb499b22c32ac32ce170b3f3590c37a0267360f6059bb74ae86b"
            },
            "downloads": -1,
            "filename": "NiceDecorator-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "0c2ae28fec9635b6836f0e48ea07492f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10, <4",
            "size": 10425,
            "upload_time": "2023-11-19T09:01:04",
            "upload_time_iso_8601": "2023-11-19T09:01:04.261913Z",
            "url": "https://files.pythonhosted.org/packages/ff/e5/05b7d1f185b2a2f2076d49b42630fc16e0366cc808f0ad14b0187e4a9432/NiceDecorator-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-19 09:01:04",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nicedecorator"
}
        
Elapsed time: 0.13644s