dmlc--dgl
828a5e5bc6
* First commit * Update * Update splitters * Update * Update * Update * Update * Update * Update * Migrate ACNN * Fix * Fix * Update * Update * Update * Update * Update * Update * Finish classification * Update * Fix * Update * Update * Update * Fix * Fix * Fix * Update * Update * Update * trigger CI * Fix CI * Update * Update * Update * Add default values * Rename * Update deprecation message
40 行
1.3 KiB
Python
40 行
1.3 KiB
Python
"""Decorator for deprecation message.
|
|
|
|
This is used in migrating the chem related code to DGL-LifeSci.
|
|
Todo(Mufei): remove it in v0.5.
|
|
|
|
The code is adapted from
|
|
https://stackoverflow.com/questions/2536307/
|
|
decorators-in-the-python-standard-lib-deprecated-specifically/48632082#48632082.
|
|
"""
|
|
import warnings
|
|
|
|
def deprecated(message, mode='func'):
|
|
"""Print formatted deprecation message.
|
|
|
|
Parameters
|
|
----------
|
|
message : str
|
|
mode : str
|
|
'func' for function and 'class' for class.
|
|
|
|
Return
|
|
------
|
|
callable
|
|
"""
|
|
assert mode in ['func', 'class']
|
|
|
|
def deprecated_decorator(func):
|
|
def deprecated_func(*args, **kwargs):
|
|
if mode == 'func':
|
|
warnings.warn("{} is deprecated and will be removed from dgl in v0.5. {}".format(
|
|
func.__name__, message), category=DeprecationWarning, stacklevel=2)
|
|
else:
|
|
warnings.warn("The class is deprecated and "
|
|
"will be removed from dgl in v0.5. {}".format(message),
|
|
category=DeprecationWarning, stacklevel=2)
|
|
warnings.simplefilter('default', DeprecationWarning)
|
|
return func(*args, **kwargs)
|
|
return deprecated_func
|
|
return deprecated_decorator
|