mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
* Grammar fixes * More changes * Grammar * Error grammar * Spelling * Grammar * REsolves grammar * grammar * grammar * grammar * grammar * grammar * grammar * grammar * grammar * "commited" > "committed" * apostrophe * more grammar * grammar * `funtion` to `function` * grammar in alias cog * grammar in cleanup cog * grammar in customcom cog * grammar in mod cog * grammar in reports cog * fix grammar in streams cog * missing apostrophe * grammar fix in trivia cog Co-authored-by: Jyu Viole Grace <24418520+thisisjvgrace@users.noreply.github.com> Co-authored-by: Jyu Viole Grace <thisisjvgrace@users.noreply.github.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import warnings
|
|
import functools
|
|
|
|
|
|
def unsafe(f, message=None):
|
|
"""
|
|
Decorator form for marking a function as unsafe.
|
|
|
|
This form may not get used much, but there are a few cases
|
|
we may want to add something unsafe generally, but safe in specific uses.
|
|
|
|
The warning can be suppressed in the safe context with warnings.catch_warnings
|
|
This should be used sparingly at most.
|
|
"""
|
|
|
|
def wrapper(func):
|
|
@functools.wraps(func)
|
|
def get_wrapped(*args, **kwargs):
|
|
actual_message = message or f"{func.__name__} is unsafe for use"
|
|
warnings.warn(actual_message, stacklevel=3, category=RuntimeWarning)
|
|
return func(*args, **kwargs)
|
|
|
|
return get_wrapped
|
|
|
|
return wrapper
|
|
|
|
|
|
def warn_unsafe(f, message=None):
|
|
"""
|
|
Function to mark function from dependencies as unsafe for use.
|
|
|
|
Warning: There is no check that a function has already been modified.
|
|
This form should only be used in init, if you want to mark an internal function
|
|
as unsafe, use the decorator form above.
|
|
|
|
The warning can be suppressed in safe contexts with warnings.catch_warnings
|
|
This should be used sparingly at most.
|
|
"""
|
|
|
|
def wrapper(func):
|
|
@functools.wraps(func)
|
|
def get_wrapped(*args, **kwargs):
|
|
actual_message = message or f"{func.__name__} is unsafe for use"
|
|
warnings.warn(actual_message, stacklevel=3, category=RuntimeWarning)
|
|
return func(*args, **kwargs)
|
|
|
|
return get_wrapped
|
|
|
|
return wrapper(f)
|