From 242a0590e6012808d2f0c0a31648df8d85177a54 Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Wed, 16 Mar 2016 09:19:04 -0400 Subject: [PATCH] Prevent meta-class error in top-level imports. Extended the `ImportError` handling hack to correctly handle the case where we cannot import submodules AND someone is extending one of the exported classes. Previously ContentMixin and ContentSettings were functions when ImportError was raised which causes really confusing errors. The correct solution here is to stop exporting stuff at the top- level and require clients to import from modules but that is for another day. --- sprockets/mixins/mediatype/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sprockets/mixins/mediatype/__init__.py b/sprockets/mixins/mediatype/__init__.py index 309506f..baeac1d 100644 --- a/sprockets/mixins/mediatype/__init__.py +++ b/sprockets/mixins/mediatype/__init__.py @@ -14,8 +14,12 @@ except ImportError as error: # pragma no cover def _error_closure(*args, **kwargs): raise error - ContentMixin = _error_closure - ContentSettings = _error_closure + class ErrorClosureClass(object): + def __init__(self, *args, **kwargs): + raise error + + ContentMixin = ErrorClosureClass + ContentSettings = ErrorClosureClass add_binary_content_type = _error_closure add_text_content_type = _error_closure set_default_content_type = _error_closure