Skip to content

Instantly share code, notes, and snippets.

@cloudhan
Created September 8, 2020 03:04
Show Gist options
  • Save cloudhan/1c64d5a445e10b6c8371a793ee01dadd to your computer and use it in GitHub Desktop.
Save cloudhan/1c64d5a445e10b6c8371a793ee01dadd to your computer and use it in GitHub Desktop.
dynamic mixin
def extend_instance(obj, cls):
"""Apply mixins to a class instance after creation"""
base_cls = obj.__class__
base_cls_name = obj.__class__.__name__
obj.__class__ = type(base_cls_name, (cls, base_cls), {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment