Created
May 25, 2020 09:55
-
-
Save chivandikwa/1790fcd3d5fe01457a17ab8719b2cbce to your computer and use it in GitHub Desktop.
Python code snippets / template / live templates (raw, pycharm and vscode)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def $NAME$(func): | |
@functools.wraps(func) | |
async def _$NAME$(*args, **kwargs): | |
# optionally do something before | |
result = await func(*args, **kwargs) | |
# optionally do something after | |
return result | |
return _$NAME$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def decorator_name(func): | |
@functools.wraps(func) | |
async def _decorator_name(*args, **kwargs): | |
# optionally do something before | |
result = await func(*args, **kwargs) | |
# optionally do something after | |
return result | |
return _decorator_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
from typing import Any | |
def $NAME$(func=None, *, param: Any): | |
def $NAME$_decorator(func): | |
@functools.wraps(func) | |
async def _$NAME$(*args, **kwargs): | |
# optionally do something before | |
result = await func(*args, **kwargs) | |
# optionally do something after | |
return result | |
return _$NAME$ | |
if func is None: | |
return $NAME$_decorator | |
else: | |
return $NAME$_decorator(func) | |
$END$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
from typing import Any | |
def decorator_name(func=None, *, param: Any): | |
def decorator_name_decorator(func): | |
@functools.wraps(func) | |
async def _decorator_name(*args, **kwargs): | |
# optionally do something before | |
result = await func(*args, **kwargs) | |
# optionally do something after | |
return result | |
return _decorator_name | |
if func is None: | |
return decorator_name_decorator | |
else: | |
return decorator_name_decorator(func) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment