Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Last active June 30, 2019 04:00
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 melvinkcx/562d3beaf86546ba4124a54d7b5771e4 to your computer and use it in GitHub Desktop.
Save melvinkcx/562d3beaf86546ba4124a54d7b5771e4 to your computer and use it in GitHub Desktop.
Snippet for "Why Refactoring? How to Refactor/Restructure Python Package?" https://hackernoon.com/why-refactoring-how-to-restructure-python-package-51b89aa91987
"""
decorators.py
"""
def refactored_class(message):
def cls_wrapper(cls):
class Wrapped(cls, object):
def __init__(self, *args, **kwargs):
warnings.warn(message, FutureWarning)
super(Wrapped, self).__init__(*args, **kwargs)
return Wrapped
return cls_wrapper
def refactored(message):
def decorator(func):
def emit_warning(*args, **kwargs):
warnings.warn(message, FutureWarning)
return func(*args, **kwargs)
return emit_warning
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment