8000 Rename child twiml methods to be the tag name and deprecate old methods by eshanholtz · Pull Request #495 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Rename child twiml methods to be the tag name and deprecate old methods #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add custom decorator to send method deprecation warning
  • Loading branch information
eshanholtz committed Oct 31, 2019
commit f 8000 68d8222b0d82480735a51095e1dcd75a2c1cebc
27 changes: 27 additions & 0 deletions tests/unit/base/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
import warnings

from twilio.base.obsolete import deprecated_method


class DeprecatedMethodTest(unittest.TestCase):

def test_deprecation_decorator(self):

@deprecated_method('new_method')
def old_method():
pass

with warnings.catch_warnings(record=True) as caught_warnings:
warnings.simplefilter("always")

# Call function that should raise a warning
old_method()

if len(caught_warnings):
self.assertEqual(
str(caught_warnings[0].message),
'Function method .old_method() is being deprecated in favor of .new_method()'
)
assert issubclass(caught_warnings[0].category, DeprecationWarning)

19 changes: 19 additions & 0 deletions twilio/base/obsolete.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,22 @@ def new_func(*args, **kwargs):
)

return new_func


def deprecated_method(new_func):
"""
This is a decorator which can be used to mark deprecated methods.
It will report in a DeprecationWarning being emitted to stderr when the deprecated method is used.
"""

def deprecated_method_wrapper(func):

@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn('Function method .{}() is being deprecated in favor of .{}()'.format(func.__name__, new_func),
DeprecationWarning)
return func(*args, **kwargs)

return wrapper

return deprecated_method_wrapper
0