Created
May 4, 2015 02:04
-
-
Save bryder/013470bb3c0cb6e2b1a1 to your computer and use it in GitHub Desktop.
How to deprecation warn on all classmethods in python
This file contains hidden or 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
def _warn(cls, func, *args, **kwargs): | |
warn("blah_class is deprecated - use BlahClass instead", DeprecationWarning) | |
return func(*args, **kwargs) | |
class blah_class(BlahClass): | |
@classmethod | |
def add_warnings(cls): | |
for attr_name, attr_value in BlahClass.__dict__.items(): | |
if isinstance(attr_value, classmethod): | |
setattr(blah_class, attr_name, partial(_warn, cls, getattr(BlahClass, attr_name))) | |
blah_class.add_warnings() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment