Created
April 15, 2011 01:27
-
-
Save peterbe/920958 to your computer and use it in GitHub Desktop.
Like an abstract class that requires you subclass certain methods but for settings. Just a thought
This file contains 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
class LazyNotImplementedError: | |
def __init__(self, error_msg): | |
self.error_msg = error_msg | |
def __call__(self, *__): | |
raise NotImplementedError(self.error_msg) | |
__str__ = __add__ = __call__ | |
# settings.py example | |
BASE = LazyNotImplementedError("You must set this in your settings_local") | |
# tests | |
try: | |
BASE + "/" | |
except NotImplementedError: | |
pass | |
try: | |
print BASE | |
except NotImplementedError: | |
pass | |
try: | |
import os | |
os.path.join(BASE, '/') | |
except NotImplementedError: | |
pass | |
try: | |
print unicode(BASE) | |
except NotImplementedError: | |
pass | |
try: | |
print repr(BASE) | |
except NotImplementedError: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment