Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created March 18, 2020 03:54
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 ychennay/4934ec461c686768c7bd633e3eb215c4 to your computer and use it in GitHub Desktop.
Save ychennay/4934ec461c686768c7bd633e3eb215c4 to your computer and use it in GitHub Desktop.
Django subclasss
def subclass_exception(name, bases, module, attached_to):
"""
Create exception subclass. Used by ModelBase below.
The exception is created in a way that allows it to be pickled, assuming
that the returned exception class will be added as an attribute to the
'attached_to' class.
"""
return type(name, bases, {
'__module__': module,
'__qualname__': '%s.%s' % (attached_to.__qualname__, name),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment