Skip to content

Instantly share code, notes, and snippets.

@chivandikwa
Created May 25, 2020 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chivandikwa/1790fcd3d5fe01457a17ab8719b2cbce to your computer and use it in GitHub Desktop.
Save chivandikwa/1790fcd3d5fe01457a17ab8719b2cbce to your computer and use it in GitHub Desktop.
Python code snippets / template / live templates (raw, pycharm and vscode)
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$
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
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$
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