Skip to content

Commit

Permalink
DeprecationUtilities.py: Add a utility function
Browse files Browse the repository at this point in the history
Add a check_deprecation utility function to log a
warning message in case deprecated parameters are
used.
  • Loading branch information
alphadose committed Jan 28, 2018
1 parent 1983e89 commit d46de38
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions coalib/misc/DeprecationUtilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging


def check_deprecation(param_list):
"""
Shows a deprecation warning message if the parameters
passed are not ``None``.
:param param_list:
A dictionary of parameters with their names mapped
to their values being checked for deprecation.
>>> from testfixtures import LogCapture
>>> from collections import OrderedDict
>>> param_list = OrderedDict([('foo', None),
... ('bar', 'Random'),
... ('baz', 1773)])
>>> with LogCapture() as capture:
... check_deprecation(param_list)
... print(capture)
root WARNING
bar parameter is deprecated
root WARNING
baz parameter is deprecated
"""
for param_name, param_value in param_list.items():
if param_value is not None:
logging.warning('{} parameter is deprecated'.format(param_name))

0 comments on commit d46de38

Please sign in to comment.