Last active
June 30, 2019 04:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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