Skip to content

Instantly share code, notes, and snippets.

@bryder
Created May 4, 2015 02:04
Show Gist options
  • Save bryder/013470bb3c0cb6e2b1a1 to your computer and use it in GitHub Desktop.
Save bryder/013470bb3c0cb6e2b1a1 to your computer and use it in GitHub Desktop.
How to deprecation warn on all classmethods in python
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